Skip to content

Commit 41ab508

Browse files
committed
Add more telemetry for project import & workspaces hash
Signed-off-by: Thomas Mäder <t.s.maeder@gmail.com>
1 parent c0a9565 commit 41ab508

File tree

3 files changed

+75
-47
lines changed

3 files changed

+75
-47
lines changed

src/standardLanguageClient.ts

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import * as net from 'net';
44
import * as path from 'path';
5-
import { CancellationToken, CodeActionKind, commands, ConfigurationTarget, DocumentSelector, EventEmitter, ExtensionContext, extensions, languages, Location, ProgressLocation, TextEditor, Uri, ViewColumn, window, workspace } from "vscode";
6-
import { ConfigurationParams, ConfigurationRequest, LanguageClientOptions, Location as LSLocation, MessageType, Position as LSPosition, TextDocumentPositionParams, WorkspaceEdit, StaticFeature, ClientCapabilities, FeatureState } from "vscode-languageclient";
5+
import { CancellationToken, CodeActionKind, commands, ConfigurationTarget, DocumentSelector, EventEmitter, ExtensionContext, extensions, languages, Location, ProgressLocation, TextEditor, Uri, ViewColumn, window, workspace, WorkspaceConfiguration } from "vscode";
6+
import { ConfigurationParams, ConfigurationRequest, LanguageClientOptions, Location as LSLocation, MessageType, Position as LSPosition, TextDocumentPositionParams, WorkspaceEdit, StaticFeature, ClientCapabilities, FeatureState, TelemetryEventNotification } from "vscode-languageclient";
77
import { LanguageClient, StreamInfo } from "vscode-languageclient/node";
88
import { apiManager } from "./apiManager";
99
import * as buildPath from './buildpath';
@@ -336,10 +336,45 @@ export class StandardLanguageClient {
336336
return result;
337337
});
338338

339+
function getJavaSettingsForTelemetry(config: WorkspaceConfiguration) {
340+
// settings whose values we can record
341+
const SETTINGS_BASIC = [
342+
"java.quickfix.showAt", "java.symbols.includeSourceMethodDeclarations",
343+
"java.completion.collapseCompletionItems", "java.completion.guessMethodArguments",
344+
"java.cleanup.actionsOnSave", "java.completion.postfix.enabled",
345+
"java.sharedIndexes.enabled", "java.inlayHints.parameterNames.enabled",
346+
"java.server.launchMode", "java.autobuild.enabled"
347+
];
348+
// settings where we only record their existence
349+
const SETTINGS_CUSTOM = [
350+
"java.settings.url", "java.format.settings.url"
351+
];
352+
353+
let value: any;
354+
const properties = {};
355+
356+
for (const key of SETTINGS_CUSTOM) {
357+
if (config.get(key)) {
358+
properties[key] = true;
359+
}
360+
}
361+
for (const key of SETTINGS_BASIC) {
362+
value = config.get(key);
363+
if (value !== undefined) {
364+
properties[key] = value;
365+
}
366+
}
367+
368+
return properties;
369+
}
370+
339371
this.languageClient.onTelemetry(async (e: TelemetryEvent) => {
340372
apiManager.fireTraceEvent(e);
341373
if (e.name === Telemetry.SERVER_INITIALIZED_EVT) {
342-
return Telemetry.sendTelemetry(Telemetry.STARTUP_EVT, e.properties);
374+
const javaSettings = getJavaSettingsForTelemetry(workspace.getConfiguration());
375+
376+
const properties= { ...e.properties, ...javaSettings };
377+
await Telemetry.sendTelemetry(Telemetry.STARTUP_EVT, );
343378
} else if (e.name === Telemetry.LS_ERROR) {
344379
const tags = [];
345380
const exception: string = e?.properties.exception;
@@ -357,8 +392,10 @@ export class StandardLanguageClient {
357392

358393
if (tags.length > 0) {
359394
e.properties['tags'] = tags;
360-
return Telemetry.sendTelemetry(Telemetry.LS_ERROR, e.properties);
395+
await Telemetry.sendTelemetry(Telemetry.LS_ERROR, e.properties);
361396
}
397+
} else if (e.name === Telemetry.IMPORT_PROJECT) {
398+
await Telemetry.sendTelemetry(Telemetry.IMPORT_PROJECT, e.properties);
362399
}
363400
});
364401

src/telemetry.ts

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { TelemetryService, getRedHatService } from "@redhat-developer/vscode-redhat-telemetry";
22
import { ExtensionContext, workspace, WorkspaceConfiguration } from "vscode";
3+
import { cyrb53 } from "./utils";
34

45
/**
56
* Wrap vscode-redhat-telemetry to suit vscode-java
@@ -10,7 +11,10 @@ export namespace Telemetry {
1011
export const COMPLETION_EVENT = "textCompletion";
1112
export const SERVER_INITIALIZED_EVT = "java.workspace.initialized";
1213
export const LS_ERROR = "java.ls.error";
14+
export const IMPORT_PROJECT = "java.workspace.importProject";
15+
1316
let telemetryManager: TelemetryService = null;
17+
let workspaceHash;
1418

1519
/**
1620
* Starts the telemetry service
@@ -22,6 +26,10 @@ export namespace Telemetry {
2226
if (!!telemetryManager) {
2327
throw new Error("The telemetry service for vscode-java has already been started");
2428
}
29+
workspaceHash = cyrb53(workspace.workspaceFolders.map(f => f.uri.toString()).join('|'));
30+
workspace.onDidChangeWorkspaceFolders(() => {
31+
workspaceHash = cyrb53(workspace.workspaceFolders.map(f => f.uri.toString()).join('|'));
32+
});
2533
const redhatService = await getRedHatService(context);
2634
const telemService = await redhatService.getTelemetryService();
2735
telemetryManager = telemService;
@@ -35,54 +43,17 @@ export namespace Telemetry {
3543
* @param data the telemetry data
3644
* @throws Error if the telemetry service has not been started yet
3745
*/
38-
export async function sendTelemetry(eventName: string, data?: any): Promise<void> {
46+
export async function sendTelemetry(eventName: string, data?: object): Promise<void> {
47+
console.log(`Sending telemetry event: ${eventName} with data: ${JSON.stringify(data)}`);
3948
if (!telemetryManager) {
4049
throw new Error("The telemetry service for vscode-java has not been started yet");
4150
}
42-
const javaSettings = getJavaSettingsForTelemetry(workspace.getConfiguration());
43-
44-
let properties: any;
45-
if (eventName === STARTUP_EVT) {
46-
properties= { ...data, ...javaSettings };
47-
} else {
48-
properties= { ...data};
49-
}
5051

51-
return telemetryManager.send({
52+
const event = {
5253
name: eventName,
53-
properties
54-
});
55-
}
56-
57-
function getJavaSettingsForTelemetry(config: WorkspaceConfiguration) {
58-
// settings whose values we can record
59-
const SETTINGS_BASIC = [
60-
"java.quickfix.showAt", "java.symbols.includeSourceMethodDeclarations",
61-
"java.completion.collapseCompletionItems", "java.completion.guessMethodArguments",
62-
"java.cleanup.actionsOnSave", "java.completion.postfix.enabled",
63-
"java.sharedIndexes.enabled", "java.inlayHints.parameterNames.enabled",
64-
"java.server.launchMode", "java.autobuild.enabled"
65-
];
66-
// settings where we only record their existence
67-
const SETTINGS_CUSTOM = [
68-
"java.settings.url", "java.format.settings.url"
69-
];
70-
71-
let value: any;
72-
const properties = {};
73-
74-
for (const key of SETTINGS_CUSTOM) {
75-
if (config.get(key)) {
76-
properties[key] = true;
77-
}
78-
}
79-
for (const key of SETTINGS_BASIC) {
80-
value = config.get(key);
81-
if (value !== undefined) {
82-
properties[key] = value;
83-
}
84-
}
54+
properties: { workspaceHash, ...data}
55+
};
8556

86-
return properties;
57+
return telemetryManager.send(event);
8758
}
8859
}

src/utils.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,3 +362,23 @@ export function getVSCodeVariablesMap(): any {
362362
keys.forEach(key => res[key] = vscodeVariables(`\${${key}}`));
363363
return res;
364364
}
365+
366+
/*
367+
* cyrb53 (c) 2018 bryc (github.com/bryc)
368+
* Public domain (or MIT if needed). Attribution appreciated.
369+
* A fast and simple 53-bit string hash function with decent collision resistance.
370+
* Largely inspired by MurmurHash2/3, but with a focus on speed/simplicity.
371+
*/
372+
export function cyrb53 (str, seed = 0) {
373+
let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
374+
for (let i = 0, ch; i < str.length; i++) {
375+
ch = str.charCodeAt(i);
376+
h1 = Math.imul(h1 ^ ch, 2654435761);
377+
h2 = Math.imul(h2 ^ ch, 1597334677);
378+
}
379+
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
380+
h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
381+
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
382+
h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
383+
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
384+
};

0 commit comments

Comments
 (0)