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

Handle disposing better #173351

Merged
merged 1 commit into from Feb 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/vs/workbench/api/common/extHostTelemetry.ts
Expand Up @@ -123,7 +123,6 @@ export class ExtHostTelemetry extends Disposable implements ExtHostTelemetryShap
this._oldTelemetryEnablement = this.getTelemetryConfiguration();
this._level = level;
const telemetryDetails = this.getTelemetryDetails();

// Loop through all loggers and update their level
this._telemetryLoggers.forEach(logger => {
logger.updateTelemetryEnablements(telemetryDetails.isUsageEnabled, telemetryDetails.isErrorsEnabled);
Expand Down Expand Up @@ -163,14 +162,14 @@ export class ExtHostTelemetryLogger {
}
}

private readonly _sender: vscode.TelemetrySender;
private readonly _onDidChangeEnableStates = new Emitter<vscode.TelemetryLogger>();
private readonly _ignoreBuiltinCommonProperties: boolean;
private readonly _additionalCommonProperties: Record<string, any> | undefined;
public readonly ignoreUnhandledExtHostErrors: boolean;

private _telemetryEnablements: { isUsageEnabled: boolean; isErrorsEnabled: boolean };
private _apiObject: vscode.TelemetryLogger | undefined;
private _sender: vscode.TelemetrySender | undefined;

constructor(
sender: vscode.TelemetrySender,
Expand Down Expand Up @@ -221,6 +220,10 @@ export class ExtHostTelemetryLogger {
}

private logEvent(eventName: string, data?: Record<string, any>): void {
// No sender means likely disposed of, we should no-op
if (!this._sender) {
return;
}
// If it's a built-in extension (vscode publisher) we don't prefix the publisher and only the ext name
if (this._extension.publisher === 'vscode') {
eventName = this._extension.name + '/' + eventName;
Expand All @@ -229,7 +232,7 @@ export class ExtHostTelemetryLogger {
}
data = this.mixInCommonPropsAndCleanData(data || {});
if (!this._inLoggingOnlyMode) {
this._sender.sendEventData(eventName, data);
this._sender?.sendEventData(eventName, data);
}
this._logger.trace(eventName, data);
}
Expand All @@ -242,7 +245,7 @@ export class ExtHostTelemetryLogger {
}

logError(eventNameOrException: Error | string, data?: Record<string, any>): void {
if (!this._telemetryEnablements.isErrorsEnabled) {
if (!this._telemetryEnablements.isErrorsEnabled || !this._sender) {
return;
}
if (typeof eventNameOrException === 'string') {
Expand Down Expand Up @@ -275,7 +278,9 @@ export class ExtHostTelemetryLogger {

dispose(): void {
if (this._sender?.flush) {
this._sender.flush();
// Disposed of so now we set it to undefined
Promise.resolve(this._sender.flush()).then(this._sender = undefined);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this._sender be unset synchronously so any callers immediately see the "disposed" behavior?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

also this._sender will stick around when flushing fails (for whatever reason)

this._apiObject = undefined;
}
}
}
Expand Down