From d993605df0b599985fbfd58a98ee0e942da81dbe Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Wed, 20 Oct 2021 13:50:23 +0100 Subject: [PATCH] Process telemetry from language server --- src/clientHandler.ts | 5 +++++ src/telemetry.ts | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/telemetry.ts diff --git a/src/clientHandler.ts b/src/clientHandler.ts index c770823a1..6db947ca6 100644 --- a/src/clientHandler.ts +++ b/src/clientHandler.ts @@ -15,6 +15,7 @@ import { import * as which from 'which'; import { CUSTOM_BIN_PATH_OPTION_NAME, ServerPath } from './serverPath'; import { ShowReferencesFeature } from './showReferences'; +import { TelemetryFeature } from './telemetry'; import { config, getFolderName, getWorkspaceFolder, normalizeFolderName, sortedWorkspaceFolders } from './vscodeUtils'; export interface TerraformLanguageClient { @@ -203,6 +204,10 @@ export class ClientHandler { client.registerFeature(new ShowReferencesFeature(client)); } + if (vscode.env.isTelemetryEnabled) { + client.registerFeature(new TelemetryFeature(client, this.reporter)); + } + client.onDidChangeState((event) => { if (event.newState === State.Stopped) { clients.delete(location); diff --git a/src/telemetry.ts b/src/telemetry.ts new file mode 100644 index 000000000..deba87639 --- /dev/null +++ b/src/telemetry.ts @@ -0,0 +1,38 @@ +import TelemetryReporter from 'vscode-extension-telemetry'; +import { BaseLanguageClient, ClientCapabilities, StaticFeature } from 'vscode-languageclient'; + +const TELEMETRY_VERSION = 1; + +type TelemetryEvent = { + v: number; + name: string; + properties: { string }; +}; + +export class TelemetryFeature implements StaticFeature { + constructor(private client: BaseLanguageClient, private reporter: TelemetryReporter) { + this.client.onTelemetry((event: TelemetryEvent) => { + if (event.v != TELEMETRY_VERSION) { + console.log(`unsupported telemetry event: ${event}`); + return; + } + + reporter.sendRawTelemetryEvent(event.name, event.properties); + }); + } + + public fillClientCapabilities(capabilities: ClientCapabilities): void { + if (!capabilities['experimental']) { + capabilities['experimental'] = {}; + } + capabilities['experimental']['telemetryVersion'] = TELEMETRY_VERSION; + } + + public initialize(): void { + return; + } + + public dispose(): void { + return; + } +}