|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT license. |
| 3 | + |
| 4 | +import * as vscode from "vscode"; |
| 5 | +import { addContextProperty, sendInfo } from "vscode-extension-telemetry-wrapper"; |
| 6 | +import { getExperimentationService, IExperimentationService, IExperimentationTelemetry, TargetPopulation } from "vscode-tas-client"; |
| 7 | + |
| 8 | +class ExperimentationTelemetry implements IExperimentationTelemetry { |
| 9 | + |
| 10 | + public setSharedProperty(name: string, value: string): void { |
| 11 | + addContextProperty(name, value); |
| 12 | + } |
| 13 | + |
| 14 | + public postEvent(eventName: string, props: Map<string, string>): void { |
| 15 | + const payload: any = { __event_name__: eventName }; |
| 16 | + for (const [key, value] of props) { |
| 17 | + payload[key] = value; |
| 18 | + } |
| 19 | + |
| 20 | + sendInfo("", payload); |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +let expService: IExperimentationService; |
| 25 | + |
| 26 | +export function getExpService() { |
| 27 | + return expService; |
| 28 | +} |
| 29 | + |
| 30 | +export function initExpService(context: vscode.ExtensionContext): void { |
| 31 | + const packageJson: {[key: string]: any} = require("../package.json"); |
| 32 | + // tslint:disable: no-string-literal |
| 33 | + const extensionName = `${packageJson["publisher"]}.${packageJson["name"]}`; |
| 34 | + const extensionVersion = packageJson["version"]; |
| 35 | + // tslint:enable: no-string-literal |
| 36 | + expService = getExperimentationService(extensionName, extensionVersion, |
| 37 | + TargetPopulation.Public, new ExperimentationTelemetry(), context.globalState); |
| 38 | +} |
0 commit comments