@@ -36,6 +36,41 @@ export function recordTelemetryStartTime(storage: vscode.Memento, date: Date) {
36
36
storage . update ( TELEMETRY_START_TIME_KEY , date . toJSON ( ) ) ;
37
37
}
38
38
39
+ /**
40
+ * TelemetryKey represents the different types of telemetry events.
41
+ */
42
+ export enum TelemetryKey {
43
+ // Indicates the installation of vscgo binary.
44
+ VSCGO_INSTALL = 'vscgo_install' ,
45
+ VSCGO_INSTALL_FAIL = 'vscgo_install_fail' ,
46
+
47
+ // Indicates the activation latency.
48
+ ACTIVATION_LATENCY_L_100MS = 'activation_latency:<100ms' ,
49
+ ACTIVATION_LATENCY_L_500MS = 'activation_latency:<500ms' ,
50
+ ACTIVATION_LATENCY_L_1000MS = 'activation_latency:<1000ms' ,
51
+ ACTIVATION_LATENCY_L_5000MS = 'activation_latency:<5000ms' ,
52
+ ACTIVATION_LATENCY_GE_5S = 'activation_latency:>=5s'
53
+ }
54
+
55
+ /**
56
+ * Categorizes a duration into a specific latency bucket.
57
+ *
58
+ * @param duration The duration in milliseconds.
59
+ * @returns The TelemetryKey representing the latency bucket.
60
+ */
61
+ export function activationLatency ( duration : number ) : TelemetryKey {
62
+ if ( duration < 100 ) {
63
+ return TelemetryKey . ACTIVATION_LATENCY_L_100MS ;
64
+ } else if ( duration < 500 ) {
65
+ return TelemetryKey . ACTIVATION_LATENCY_L_500MS ;
66
+ } else if ( duration < 1000 ) {
67
+ return TelemetryKey . ACTIVATION_LATENCY_L_1000MS ;
68
+ } else if ( duration < 5000 ) {
69
+ return TelemetryKey . ACTIVATION_LATENCY_L_5000MS ;
70
+ }
71
+ return TelemetryKey . ACTIVATION_LATENCY_GE_5S ;
72
+ }
73
+
39
74
function readTelemetryStartTime ( storage : vscode . Memento ) : Date | null {
40
75
const value = storage . get < string | number | Date > ( TELEMETRY_START_TIME_KEY ) ;
41
76
if ( ! value ) {
@@ -109,12 +144,12 @@ export class TelemetryReporter implements vscode.Disposable {
109
144
/**
110
145
* Adds a numeric value to a counter associated with the given key.
111
146
*/
112
- public add ( key : string , value : number ) {
147
+ public add ( key : TelemetryKey , value : number ) {
113
148
if ( value <= 0 ) {
114
149
return ;
115
150
}
116
- key = key . replace ( / [ \s \n ] / g, '_' ) ;
117
- this . _counters [ key ] = ( this . _counters [ key ] || 0 ) + value ;
151
+ const sanitized = key . replace ( / [ \s \n ] / g, '_' ) ;
152
+ this . _counters [ sanitized ] = ( this . _counters [ sanitized ] || 0 ) + value ;
118
153
}
119
154
120
155
/**
@@ -197,7 +232,7 @@ export const telemetryReporter = new TelemetryReporter();
197
232
198
233
// TODO(hyangah): consolidate the list of all the telemetries and bucketting functions.
199
234
200
- export function addTelemetryEvent ( name : string , count : number ) {
235
+ export function addTelemetryEvent ( name : TelemetryKey , count : number ) {
201
236
telemetryReporter . add ( name , count ) ;
202
237
}
203
238
0 commit comments