Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telemetry patch #457

Merged
merged 5 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const advancedOptions: JupyterFrontEndPlugin<Scheduler.IAdvancedOptions> = {
const telemetryHandler = async (
eventLog: Scheduler.IEventLog
): Promise<void> => {
console.log(JSON.stringify(eventLog, undefined, 4));
// console.log(JSON.stringify(eventLog, undefined, 4));
};

const telemetry: JupyterFrontEndPlugin<Scheduler.TelemetryHandler> = {
3coins marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -182,13 +182,26 @@ async function activatePlugin(
let mainAreaWidget: MainAreaWidget<NotebookJobsPanel> | undefined;
let jobsPanel: NotebookJobsPanel | undefined;

const eventLogger: Scheduler.EventLogger = eventName => {
if (!eventName) {
return;
}
const eventLog = {
body: {
name: `org.jupyter.jupyter-scheduler.${eventName}`
},
timestamp: new Date()
};
telemetryHandler(eventLog).then();
};

const showJobsPanel = async (data: IJobsModel) => {
if (!mainAreaWidget || mainAreaWidget.isDisposed) {
// Create new jobs panel widget
jobsPanel = new NotebookJobsPanel({
app,
translator,
telemetryHandler,
eventLogger,
advancedOptions: advancedOptions
});
// Create new main area widget
Expand Down Expand Up @@ -223,13 +236,19 @@ async function activatePlugin(
// Commands

commands.addCommand(CommandIDs.showNotebookJobs, {
execute: async args => showJobsPanel(args as IJobsModel),
execute: async args => {
if (args['launcher']) {
eventLogger('launcher.show-jobs');
}
dlqqq marked this conversation as resolved.
Show resolved Hide resolved
showJobsPanel(args as IJobsModel);
},
label: trans.__('Notebook Jobs'),
icon: eventNoteIcon
});

commands.addCommand(CommandIDs.createJobFileBrowser, {
execute: async () => {
eventLogger('file-browser.create-job');
const widget = fileBrowserTracker.currentWidget;
const filePath = getSelectedFilePath(widget) ?? '';

Expand All @@ -252,6 +271,7 @@ async function activatePlugin(

commands.addCommand(CommandIDs.createJobCurrentNotebook, {
execute: async () => {
eventLogger('notebook-header.create-job');
// Get the current notebook's name and path
const contentsModel =
notebookTracker.currentWidget?.context?.contentsModel;
Expand Down Expand Up @@ -302,7 +322,10 @@ async function activatePlugin(
// Add to launcher
if (launcher) {
launcher.add({
command: CommandIDs.showNotebookJobs
command: CommandIDs.showNotebookJobs,
args: {
launcher: true
}
});
}
}
Expand Down
21 changes: 4 additions & 17 deletions src/notebook-jobs-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class NotebookJobsPanel extends VDomRenderer<JobsModel> {
readonly _translator: ITranslator;
readonly _trans: TranslationBundle;
readonly _advancedOptions: React.FunctionComponent<Scheduler.IAdvancedOptionsProps>;
readonly _telemetryHandler: Scheduler.TelemetryHandler;
readonly _eventLogger: Scheduler.EventLogger;
private _newlyCreatedId: string | undefined;
private _newlyCreatedName: string | undefined;
private _last_input_drop_target: Element | null;
Expand All @@ -68,7 +68,7 @@ export class NotebookJobsPanel extends VDomRenderer<JobsModel> {
this._translator = options.translator;
this._trans = this._translator.load('jupyterlab');
this._advancedOptions = options.advancedOptions;
this._telemetryHandler = options.telemetryHandler;
this._eventLogger = options.eventLogger;
this._last_input_drop_target = null;

this.node.setAttribute('role', 'region');
Expand Down Expand Up @@ -124,19 +124,6 @@ export class NotebookJobsPanel extends VDomRenderer<JobsModel> {
}
};

logEvent(eventName: string): void {
if (!eventName) {
return;
}
const eventLog = {
body: {
name: `org.jupyter.jupyter-scheduler.${eventName}`
},
timestamp: new Date()
};
this._telemetryHandler(eventLog).then();
}

/**
* Handle the DOM events for the directory listing.
*
Expand Down Expand Up @@ -235,7 +222,7 @@ export class NotebookJobsPanel extends VDomRenderer<JobsModel> {
return (
<ThemeProvider theme={getJupyterLabTheme()}>
<TranslatorContext.Provider value={this._translator}>
<LogContext.Provider value={this.logEvent.bind(this)}>
<LogContext.Provider value={this._eventLogger.bind(this)}>
<ErrorBoundary
alertTitle={this._trans.__('Internal error')}
alertMessage={this._trans.__(
Expand Down Expand Up @@ -325,7 +312,7 @@ namespace NotebookJobsPanel {
app: JupyterFrontEnd;
translator: ITranslator;
advancedOptions: Scheduler.IAdvancedOptions;
telemetryHandler: Scheduler.TelemetryHandler;
eventLogger: Scheduler.EventLogger;
model?: JobsModel;
}
}
2 changes: 2 additions & 0 deletions src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@ export namespace Scheduler {
export const TelemetryHandler = new Token<TelemetryHandler>(
'@jupyterlab/scheduler:ITelemetryHandler'
);

export type EventLogger = (eventName: string) => void;
}
Loading