|
1 | 1 | import type { TelemetryReporter as VSCodeTelemetryReporter } from "@vscode/extension-telemetry"; |
| 2 | +import type { IExperimentationTelemetry } from "vscode-tas-client"; |
2 | 3 |
|
3 | 4 | // As new events are added, update the TelemetryReporter interface below. |
4 | 5 | // This helps ensure that the telemetry events used in the codebase are |
@@ -27,21 +28,45 @@ export interface TelemetryReporter { |
27 | 28 | dispose(): void; |
28 | 29 | } |
29 | 30 |
|
30 | | -export function createTelemetryReporter(vscReporter: VSCodeTelemetryReporter): TelemetryReporter { |
| 31 | +export interface ExperimentationTelemetryReporter extends TelemetryReporter, IExperimentationTelemetry {} |
| 32 | + |
| 33 | +// Note: |
| 34 | +// This reporter *supports* experimentation telemetry, |
| 35 | +// but will only do so when passed to an `ExperimentationService` which |
| 36 | +// will set shared properties on this reporter. |
| 37 | +export function createTelemetryReporter(vscReporter: VSCodeTelemetryReporter): ExperimentationTelemetryReporter { |
| 38 | + let sharedProperties: Record<string, string> = Object.create(null); |
| 39 | + |
31 | 40 | return { |
| 41 | + // Primary reporting methods for the extension. |
32 | 42 | sendTelemetryEvent, |
33 | 43 | sendTelemetryErrorEvent, |
34 | 44 | sendTelemetryEventUntyped: sendTelemetryEvent, |
35 | 45 | sendTelemetryErrorEventUntyped: sendTelemetryErrorEvent, |
36 | 46 |
|
| 47 | + // Required for the experimentation telemetry service interface. |
| 48 | + setSharedProperty, |
| 49 | + postEvent, |
| 50 | + |
37 | 51 | dispose: () => vscReporter.dispose(), |
38 | 52 | }; |
39 | 53 |
|
| 54 | + function setSharedProperty(key: string, value: string): void { |
| 55 | + sharedProperties[key] = value; |
| 56 | + } |
| 57 | + |
| 58 | + function postEvent(eventName: string, props: Map<string, string>): void { |
| 59 | + const propsAsObj = { ...sharedProperties, ...Object.fromEntries(props) }; |
| 60 | + vscReporter.sendTelemetryEvent(eventName, propsAsObj); |
| 61 | + } |
| 62 | + |
40 | 63 | function sendTelemetryEvent(eventName: string, data?: Record<string, string>, measurements?: Record<string, number>): void { |
| 64 | + data = { ...sharedProperties, ...data }; |
41 | 65 | vscReporter.sendTelemetryEvent(eventName, data, measurements); |
42 | 66 | } |
43 | 67 |
|
44 | 68 | function sendTelemetryErrorEvent(eventName: string, data?: Record<string, string>, measurements?: Record<string, number>): void { |
| 69 | + data = { ...sharedProperties, ...data }; |
45 | 70 | vscReporter.sendTelemetryErrorEvent(eventName, data, measurements); |
46 | 71 | } |
47 | 72 | } |
|
0 commit comments