1
>
/*---------------------------------------------------------------------------------------------
telemetry.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { createDecorator } from '../../instantiation/common/instantiation.js';
7
>
import { ClassifiedEvent, IGDPRProperty, OmitMetadata, StrictPropertyCheck } from './gdprTypings.js';
8
>
9
>
export const ITelemetryService = createDecorator<ITelemetryService>('telemetryService');
10
>
11
>
export interface ITelemetryData {
12
>
from?: string;
13
>
target?: string;
14
>
[key: string]: string | unknown | undefined;
15
>
}
16
>
17
>
export interface ITelemetryService {
18
>
19
>
readonly _serviceBrand: undefined;
20
>
21
>
readonly telemetryLevel: TelemetryLevel;
22
>
23
>
readonly sessionId: string;
24
>
readonly machineId: string;
25
>
readonly sqmId: string;
26
>
readonly devDeviceId: string;
27
>
readonly firstSessionDate: string;
28
>
readonly msftInternal?: boolean;
29
>
30
>
/**
31
>
* Whether error telemetry will get sent. If false, `publicLogError` will no-op.
32
>
*/
33
>
readonly sendErrorTelemetry: boolean;
34
>
35
>
/**
36
>
* @deprecated Use publicLog2 and the typescript GDPR annotation where possible
37
>
*/
38
>
publicLog(eventName: string, data?: ITelemetryData): void;
39
>
40
>
/**
41
>
* Sends a telemetry event that has been privacy approved.
42
>
* Do not call this unless you have been given approval.
43
>
*/
44
>
publicLog2<E extends ClassifiedEvent<OmitMetadata<T>> = never, T extends IGDPRProperty = never>(eventName: string, data?: StrictPropertyCheck<T, E>): void;
45
>
46
>
/**
47
>
* @deprecated Use publicLogError2 and the typescript GDPR annotation where possible
48
>
*/
49
>
publicLogError(errorEventName: string, data?: ITelemetryData): void;
50
>
51
>
publicLogError2<E extends ClassifiedEvent<OmitMetadata<T>> = never, T extends IGDPRProperty = never>(eventName: string, data?: StrictPropertyCheck<T, E>): void;
52
>
53
>
setExperimentProperty(name: string, value: string): void;
54
>
55
>
/**
56
>
* Sets a common property that will be attached to all telemetry events.
57
>
* Common properties are added after PII cleaning and cannot be overridden by event data.
58
>
*/
59
>
setCommonProperty(name: string, value: string | boolean): void;
60
>
}
61
>
62
>
export function telemetryLevelEnabled(service: ITelemetryService, level: TelemetryLevel): boolean {
63
return service.telemetryLevel >= level;
64
}
66
>
/**
67
>
* Replaces `/` and `\` with `|` in model identifiers to prevent the
68
>
* telemetry pipeline from redacting them as file paths.
69
>
*/
70
>
export function escapeModelIdForTelemetry(modelId: string | undefined): string | undefined {
71
return modelId?.replace(/[\/\\]/g, '|');
72
}
74
>
export interface ITelemetryEndpoint {
75
>
id: string;
76
>
aiKey: string;
77
>
sendErrorTelemetry: boolean;
78
>
}
79
>
80
>
export const ICustomEndpointTelemetryService = createDecorator<ICustomEndpointTelemetryService>('customEndpointTelemetryService');
81
>
82
>
export interface ICustomEndpointTelemetryService {
83
>
readonly _serviceBrand: undefined;
84
>
85
>
publicLog(endpoint: ITelemetryEndpoint, eventName: string, data?: ITelemetryData): void;
86
>
publicLogError(endpoint: ITelemetryEndpoint, errorEventName: string, data?: ITelemetryData): void;
87
>
}
88
>
89
>
// Keys
90
>
export const currentSessionDateStorageKey = 'telemetry.currentSessionDate';
91
>
export const firstSessionDateStorageKey = 'telemetry.firstSessionDate';
92
>
export const lastSessionDateStorageKey = 'telemetry.lastSessionDate';
93
>
export const machineIdKey = 'telemetry.machineId';
94
>
export const sqmIdKey = 'telemetry.sqmId';
95
>
export const devDeviceIdKey = 'telemetry.devDeviceId';
96
>
97
>
// Configuration Keys
98
>
export const TELEMETRY_SECTION_ID = 'telemetry';
99
>
export const TELEMETRY_SETTING_ID = 'telemetry.telemetryLevel';
100
>
export const TELEMETRY_CRASH_REPORTER_SETTING_ID = 'telemetry.enableCrashReporter';
101
>
export const TELEMETRY_OLD_SETTING_ID = 'telemetry.enableTelemetry';
102
>
103
>
export const enum TelemetryLevel {
104
>
NONE = 0,
105
>
CRASH = 1,
106
>
ERROR = 2,
107
>
USAGE = 3
108
>
}
109
>
110
>
export const enum TelemetryConfiguration {
111
>
OFF = 'off',
112
>
CRASH = 'crash',
113
>
ERROR = 'error',
114
>
ON = 'all'
115
>
}
116
>
117
>
export interface ICommonProperties {
118
>
[name: string]: string | boolean | undefined;
119
>
}