mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-19 09:35:36 -05:00
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:
@@ -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 { }
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user