forked from microsoft/vscode-pull-request-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexperimentationService.ts
More file actions
126 lines (108 loc) · 3.52 KB
/
Copy pathexperimentationService.ts
File metadata and controls
126 lines (108 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import TelemetryReporter from 'vscode-extension-telemetry';
import {
getExperimentationService,
IExperimentationService,
IExperimentationTelemetry,
TargetPopulation,
} from 'vscode-tas-client';
/* __GDPR__
"query-expfeature" : {
"ABExp.queriedFeature": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
export class ExperimentationTelemetry implements IExperimentationTelemetry {
private sharedProperties: Record<string, string> = {};
constructor(private baseReporter: TelemetryReporter | undefined) { }
sendTelemetryEvent(eventName: string, properties?: Record<string, string>, measurements?: Record<string, number>) {
this.baseReporter?.sendTelemetryEvent(
eventName,
{
...this.sharedProperties,
...properties,
},
measurements,
);
}
sendTelemetryErrorEvent(
eventName: string,
properties?: Record<string, string>,
_measurements?: Record<string, number>,
) {
this.baseReporter?.sendTelemetryErrorEvent(eventName, {
...this.sharedProperties,
...properties,
});
}
setSharedProperty(name: string, value: string): void {
this.sharedProperties[name] = value;
}
postEvent(eventName: string, props: Map<string, string>): void {
const event: Record<string, string> = {};
for (const [key, value] of props) {
event[key] = value;
}
this.sendTelemetryEvent(eventName, event);
}
async dispose(): Promise<any> {
return this.baseReporter?.dispose();
}
}
function getTargetPopulation(): TargetPopulation {
switch (vscode.env.uriScheme) {
case 'vscode':
return TargetPopulation.Public;
case 'vscode-insiders':
return TargetPopulation.Insiders;
case 'vscode-exploration':
return TargetPopulation.Internal;
case 'code-oss':
return TargetPopulation.Team;
default:
return TargetPopulation.Public;
}
}
class NullExperimentationService implements IExperimentationService {
readonly initializePromise: Promise<void> = Promise.resolve();
isFlightEnabled(_flight: string): boolean {
return false;
}
isCachedFlightEnabled(_flight: string): Promise<boolean> {
return Promise.resolve(false);
}
isFlightEnabledAsync(_flight: string): Promise<boolean> {
return Promise.resolve(false);
}
getTreatmentVariable<T extends boolean | number | string>(_configId: string, _name: string): T | undefined {
return undefined;
}
getTreatmentVariableAsync<T extends boolean | number | string>(
_configId: string,
_name: string,
): Promise<T | undefined> {
return Promise.resolve(undefined);
}
}
export async function createExperimentationService(
context: vscode.ExtensionContext,
experimentationTelemetry: ExperimentationTelemetry,
): Promise<IExperimentationService> {
const id = context.extension.id;
const name = context.extension.packageJSON['name'];
const version = context.extension.packageJSON['version'];
const targetPopulation = getTargetPopulation();
// We only create a real experimentation service for the stable version of the extension, not insiders.
return name === 'vscode-pull-request-github'
? getExperimentationService(
id,
version,
targetPopulation,
experimentationTelemetry,
context.globalState,
)
: new NullExperimentationService();
}