Skip to content

Commit

Permalink
Process telemetry from language server
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Nov 11, 2021
1 parent a19ba55 commit d993605
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/clientHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
38 changes: 38 additions & 0 deletions src/telemetry.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit d993605

Please sign in to comment.