Remove TelemetryUtils and use IAdsTelemetryService directly (#8289)

* Remove TelemetryUtils and use IAdsTelemetryService directly

* Fix event names and cleanup

* Fix tests

* Fix strict null check
This commit is contained in:
Charles Gagnon
2019-11-13 13:54:55 -08:00
committed by GitHub
parent 86d6295bf0
commit 18ab2ae799
39 changed files with 179 additions and 313 deletions

View File

@@ -55,6 +55,18 @@ class TelemetryEventImpl implements ITelemetryEvent {
}
}
class NullTelemetryEventImpl implements ITelemetryEvent {
constructor() { }
public send(): void { }
public withAdditionalProperties(additionalProperties: ITelemetryEventProperties): ITelemetryEvent { return this; }
public withAdditionalMeasurements(additionalMeasurements: ITelemetryEventMeasures): ITelemetryEvent { return this; }
public withConnectionInfo(connectionInfo: ITelemetryConnectionInfo): ITelemetryEvent { return this; }
}
export class AdsTelemetryService implements IAdsTelemetryService {
_serviceBrand: undefined;
@@ -188,3 +200,31 @@ export class AdsTelemetryService implements IAdsTelemetryService {
this.createTelemetryEvent(eventName, properties, measurements).send();
}
}
export class NullAdsTelemetryService implements IAdsTelemetryService {
_serviceBrand: undefined;
get isOptedIn(): boolean {
return false;
}
setEnabled(value: boolean): void { }
getTelemetryInfo(): Promise<ITelemetryInfo> {
return Promise.resolve({
sessionId: '',
machineId: '',
instanceId: ''
});
}
createViewEvent(view: string): ITelemetryEvent { return new NullTelemetryEventImpl(); }
sendViewEvent(view: string): void { }
createActionEvent(view: string, action: string, target?: string, source?: string, durationInMs?: number): ITelemetryEvent { return new NullTelemetryEventImpl(); }
sendActionEvent(view: string, action: string, target?: string, source?: string, durationInMs?: number): void { }
createMetricsEvent(metrics: ITelemetryEventMeasures, groupName: string): ITelemetryEvent { return new NullTelemetryEventImpl(); }
sendMetricsEvent(metrics: ITelemetryEventMeasures, groupName: string): void { }
createErrorEvent(view: string, name: string, errorCode?: string, errorType?: string): ITelemetryEvent { return new NullTelemetryEventImpl(); }
sendErrorEvent(view: string, name: string, errorCode?: string, errorType?: string): void { }
createTelemetryEvent(eventName: string, properties?: ITelemetryEventProperties, measurements?: ITelemetryEventMeasures): ITelemetryEvent { return new NullTelemetryEventImpl(); }
sendTelemetryEvent(eventName: string, properties?: ITelemetryEventProperties, measurements?: ITelemetryEventMeasures): void { }
}

View File

@@ -11,7 +11,7 @@ export const IAdsTelemetryService = createDecorator<IAdsTelemetryService>('adsTe
* Holds additional properties to send along with an event.
*/
export interface ITelemetryEventProperties {
[key: string]: string;
[key: string]: any;
}
/**

View File

@@ -1,62 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ITelemetryService, ITelemetryData } from 'vs/platform/telemetry/common/telemetry';
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
import { ILogService } from 'vs/platform/log/common/log';
export interface IConnectionTelemetryData extends ITelemetryData {
provider?: string;
}
/**
* Call the given telemetry service to log the telemetry event.
* If the provider is not in the data, tries to get it from connection inside the data.
* The connection in the data won't be included in the telemetry data
* Note: userId is added to all telemetry events so no need to add it here
* @param telemetryService Telemetry Service
* @param telemetryEventName Telemetry event name
* @param data Telemetry data
*/
export function addTelemetry(
telemetryService: ITelemetryService,
logService: ILogService,
telemetryEventName: string,
data?: IConnectionTelemetryData,
connection?: IConnectionProfile
): Promise<void> {
return new Promise<void>(resolve => {
try {
let telData: ITelemetryData = data === undefined ? {} : data;
if (telData && telData.provider === undefined) {
let provider: string = '';
if (connection) {
provider = connection.providerName;
}
telData.provider = provider;
}
delete telData['connection'];
if (telemetryService) {
telemetryService.publicLog(telemetryEventName, telData).then(() => {
resolve();
}, telemetryServiceError => {
if (logService) {
logService.warn(`Failed to add telemetry. error: ${telemetryServiceError}`);
}
resolve();
});
} else {
resolve();
}
} catch (error) {
if (logService) {
logService.warn(`Failed to add telemetry. error: ${error}`);
}
resolve();
}
});
}