Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process telemetry from language server #823

Merged
merged 3 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/clientHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from 'vscode-languageclient/node';
import { ServerPath } from './serverPath';
import { ShowReferencesFeature } from './showReferences';
import { TelemetryFeature } from './telemetry';
import { config } from './vscodeUtils';

export interface TerraformLanguageClient {
Expand Down Expand Up @@ -89,6 +90,10 @@ export class ClientHandler {
client.registerFeature(new ShowReferencesFeature(client));
}

if (vscode.env.isTelemetryEnabled) {
client.registerFeature(new TelemetryFeature(client, this.reporter));
}

client.onDidChangeState((event) => {
console.log(`Client: ${State[event.oldState]} --> ${State[event.newState]}`);
if (event.newState === State.Stopped) {
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: { [key: string]: unknown };
};

export class TelemetryFeature implements StaticFeature {
constructor(private client: BaseLanguageClient, reporter: TelemetryReporter) {
this.client.onTelemetry((event: TelemetryEvent) => {
radeksimko marked this conversation as resolved.
Show resolved Hide resolved
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;
}
}