diff --git a/USAGE_DATA.md b/USAGE_DATA.md index e97a20529..ed5e1d221 100644 --- a/USAGE_DATA.md +++ b/USAGE_DATA.md @@ -18,7 +18,8 @@ vscode-java has opt-in telemetry collection, provided by [vscode-redhat-telemetr * `java.settings.url`, `java.format.settings.url`, `java.quickfix.showAt`, `java.symbols.includeSourceMethodDeclarations`, `java.completion.guessMethodArguments`, `java.completion.postfix.enabled`, `java.cleanup.actionsOnSave`, `java.sharedIndexes.enabled`, `java.inlayHints.parameterNames.enabled`, `java.server.launchMode`, `java.autobuild.enabled` * The extension name and the choice made when a recommendation to install a 3rd party extension is proposed * The name of Java commands being manually executed, and any resulting errors - + * The number of results (eg. 20), whether an error occured (eg. false), and duration (in milliseconds) when code assist is activated + ## What's included in the general telemetry data Please see the diff --git a/src/standardLanguageClient.ts b/src/standardLanguageClient.ts index ab70fdf51..092821187 100644 --- a/src/standardLanguageClient.ts +++ b/src/standardLanguageClient.ts @@ -5,13 +5,13 @@ import { findRuntimes } from "jdk-utils"; import * as net from 'net'; import * as path from 'path'; import { CancellationToken, CodeActionKind, commands, ConfigurationTarget, DocumentSelector, EventEmitter, ExtensionContext, extensions, languages, Location, ProgressLocation, TextEditor, Uri, ViewColumn, window, workspace } from "vscode"; -import { ConfigurationParams, ConfigurationRequest, LanguageClientOptions, Location as LSLocation, MessageType, Position as LSPosition, TextDocumentPositionParams, WorkspaceEdit } from "vscode-languageclient"; +import { ConfigurationParams, ConfigurationRequest, LanguageClientOptions, Location as LSLocation, MessageType, Position as LSPosition, TextDocumentPositionParams, WorkspaceEdit, CompletionRequest } from "vscode-languageclient"; import { LanguageClient, StreamInfo } from "vscode-languageclient/node"; import { apiManager } from "./apiManager"; import * as buildPath from './buildpath'; import { javaRefactorKinds, RefactorDocumentProvider } from "./codeActionProvider"; import { Commands } from "./commands"; -import { ClientStatus } from "./extension.api"; +import { ClientStatus, TraceEvent } from "./extension.api"; import * as fileEventHandler from './fileEventHandler'; import { gradleCodeActionMetadata, GradleCodeActionProvider } from "./gradle/gradleCodeActionProvider"; import { awaitServerConnection, prepareExecutable, DEBUG } from "./javaServerStarter"; @@ -148,6 +148,7 @@ export class StandardLanguageClient { // Disable the client-side snippet provider since LS is ready. snippetCompletionProvider.dispose(); registerDocumentValidationListener(context, this.languageClient); + registerCodeCompletionTelemetryListener(); break; case 'Started': this.status = ClientStatus.started; @@ -735,3 +736,20 @@ export async function applyWorkspaceEdit(workspaceEdit: WorkspaceEdit, languageC return Promise.resolve(true); } } + +export function registerCodeCompletionTelemetryListener() { + apiManager.getApiInstance().onDidRequestEnd((traceEvent: TraceEvent) => { + if (traceEvent.type === CompletionRequest.method) { + // Exclude the invalid completion requests. + if (!traceEvent.resultLength) { + return; + } + const props = { + duration: Math.round(traceEvent.duration * 100) / 100, + resultLength: traceEvent.resultLength || 0, + error: !!traceEvent.error, + }; + return Telemetry.sendTelemetry(Telemetry.COMPLETION_EVENT, props); + } + }); +} \ No newline at end of file diff --git a/src/telemetry.ts b/src/telemetry.ts index d930123df..64a019075 100644 --- a/src/telemetry.ts +++ b/src/telemetry.ts @@ -7,6 +7,7 @@ import { ExtensionContext, workspace, WorkspaceConfiguration } from "vscode"; export namespace Telemetry { export const STARTUP_EVT = "startup"; + export const COMPLETION_EVENT = "textCompletion"; export const SERVER_INITIALIZED_EVT = "java.workspace.initialized"; let telemetryManager: TelemetryService = null; let serverInitializedReceived = false;