mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 01:58:53 +01:00
Add common service for logging deprecated api usage (#88585)
* Add common service for logging deprecated api usage For #88391 Adds a new `ExtHostApiDeprecationService`. This service logs a warning and telemetry when a deprecated API is used. Updates some of the more simple deprecated apis to use this new service * Note that extensionId cannot be undefined * Fix event name
This commit is contained in:
71
src/vs/workbench/api/common/extHostApiDeprecationService.ts
Normal file
71
src/vs/workbench/api/common/extHostApiDeprecationService.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import * as extHostProtocol from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
|
||||
|
||||
export interface IExtHostApiDeprecationService {
|
||||
_serviceBrand: undefined;
|
||||
|
||||
report(apiId: string, extension: IExtensionDescription, migrationSuggestion: string): void;
|
||||
}
|
||||
|
||||
export const IExtHostApiDeprecationService = createDecorator<IExtHostApiDeprecationService>('IExtHostApiDeprecationService');
|
||||
|
||||
export class ExtHostApiDeprecationService implements IExtHostApiDeprecationService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
private readonly _reportedUsages = new Set<string>();
|
||||
private readonly _telemetryShape: extHostProtocol.MainThreadTelemetryShape;
|
||||
|
||||
constructor(
|
||||
@IExtHostRpcService rpc: IExtHostRpcService,
|
||||
@ILogService private readonly _extHostLogService: ILogService,
|
||||
) {
|
||||
this._telemetryShape = rpc.getProxy(extHostProtocol.MainContext.MainThreadTelemetry);
|
||||
}
|
||||
|
||||
public report(apiId: string, extension: IExtensionDescription, migrationSuggestion: string): void {
|
||||
const key = this.getUsageKey(apiId, extension);
|
||||
if (this._reportedUsages.has(key)) {
|
||||
return;
|
||||
}
|
||||
this._reportedUsages.add(key);
|
||||
|
||||
if (extension.isUnderDevelopment) {
|
||||
this._extHostLogService.warn(`[Deprecation Warning] '${apiId}' is deprecated. ${migrationSuggestion}`);
|
||||
}
|
||||
|
||||
type DeprecationTelemetry = {
|
||||
extensionId: string;
|
||||
apiId: string;
|
||||
};
|
||||
type DeprecationTelemetryMeta = {
|
||||
extensionId: { classification: 'SystemMetaData', purpose: 'PerformanceAndHealth' };
|
||||
apiId: { classification: 'SystemMetaData', purpose: 'PerformanceAndHealth' };
|
||||
};
|
||||
this._telemetryShape.$publicLog2<DeprecationTelemetry, DeprecationTelemetryMeta>('extHostDeprecatedApiUsage', {
|
||||
extensionId: extension.identifier.value,
|
||||
apiId: apiId,
|
||||
});
|
||||
}
|
||||
|
||||
private getUsageKey(apiId: string, extension: IExtensionDescription): string {
|
||||
return `${apiId}-${extension.identifier.value}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const NullApiDeprecationService = Object.freeze(new class implements IExtHostApiDeprecationService {
|
||||
_serviceBrand: undefined;
|
||||
|
||||
public report(_apiId: string, _extension: IExtensionDescription, _warningMessage: string): void {
|
||||
// noop
|
||||
}
|
||||
}());
|
||||
Reference in New Issue
Block a user