Skip to content

Commit

Permalink
Initialize telemetry data only once (#15537)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne authored Apr 11, 2024
1 parent 4810b08 commit f805e83
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/kernels/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,16 +422,7 @@ abstract class BaseKernel implements IBaseKernel {
}
});
const notebook = workspace.notebookDocuments.find((item) => item.uri.toString() === this.uri.toString());
const telemetryTracker = notebook
? getNotebookTelemetryTracker(notebook)?.jupyterSessionTelemetry()
: undefined;
if (!this.startupUI.disableUI) {
// This means the user is actually running something against the kernel (deliberately).
await initializeInteractiveOrNotebookTelemetryBasedOnUserAction(
this.resourceUri,
this.kernelConnectionMetadata
);
} else {
if (this.startupUI.disableUI) {
this.startupUI.onDidChangeDisableUI(
() => {
if (this.disposing || this.disposed || this.startupUI.disableUI) {
Expand All @@ -454,16 +445,26 @@ abstract class BaseKernel implements IBaseKernel {

if (!this._jupyterSessionPromise) {
const stopWatch = new StopWatch();
await trackKernelResourceInformation(this.resourceUri, {
kernelConnection: this.kernelConnectionMetadata,
actionSource: this.creator
});
if (this.disposing) {
throw new CancellationError();
}
telemetryTracker?.stop();
Cancellation.throwIfCanceled(this.startCancellation.token);
this._jupyterSessionPromise = this.createJupyterSession()

const initializeTelemetry = async () => {
const telemetryTracker = notebook
? getNotebookTelemetryTracker(notebook)?.jupyterSessionTelemetry()
: undefined;
await trackKernelResourceInformation(this.resourceUri, {
kernelConnection: this.kernelConnectionMetadata,
actionSource: this.creator,
// This means the user is actually running something against the kernel (deliberately).
userExecutedCell: !this.startupUI.disableUI
});
if (this.disposing) {
throw new CancellationError();
}
telemetryTracker?.stop();
Cancellation.throwIfCanceled(this.startCancellation.token);
};

this._jupyterSessionPromise = initializeTelemetry()
.then(() => this.createJupyterSession())
.then((session) => {
sendKernelTelemetryEvent(this.resourceUri, Telemetry.PerceivedJupyterStartupNotebook, {
duration: stopWatch.elapsedTime
Expand Down

0 comments on commit f805e83

Please sign in to comment.