Skip to content

Commit 3c95bae

Browse files
authored
Merge pull request #403 from Achal1607/telemetry
Enhancement in telemetry preferences flow and some telemetry maintenance changes
2 parents 6d1c399 + 13182aa commit 3c95bae

24 files changed

+605
-99
lines changed

vscode/esbuild.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ const createTelemetryConfig = () => {
5757
baseUrl: null,
5858
baseEndpoint: "/vscode/java/sendTelemetry",
5959
version: "/v1"
60+
},
61+
metadata: {
62+
consentSchemaVersion: "v1"
6063
}
6164
}
6265

@@ -73,6 +76,9 @@ const createTelemetryConfig = () => {
7376
baseUrl: process.env.TELEMETRY_API_BASE_URL,
7477
baseEndpoint: process.env.TELEMETRY_API_ENDPOINT,
7578
version: process.env.TELEMETRY_API_VERSION
79+
},
80+
metadata: {
81+
consentSchemaVersion: process.env.CONSENT_SCHEMA_VERSION
7682
}
7783
});
7884

vscode/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,10 @@
245245
"jdk.telemetry.enabled": {
246246
"type": "boolean",
247247
"description": "%jdk.configuration.telemetry.enabled.description%",
248-
"default": false
248+
"default": false,
249+
"tags": [
250+
"telemetry"
251+
]
249252
}
250253
}
251254
},

vscode/src/telemetry/config.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2024, Oracle and/or its affiliates.
2+
Copyright (c) 2024-2025, Oracle and/or its affiliates.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
import { RetryConfig, TelemetryApi } from "./types";
16+
import { RetryConfig, TelemetryApi, TelemetryConfigMetadata } from "./types";
1717
import * as path from 'path';
1818
import * as fs from 'fs';
1919
import { LOGGER } from "../logger";
@@ -24,6 +24,7 @@ export class TelemetryConfiguration {
2424
private static instance: TelemetryConfiguration;
2525
private retryConfig!: RetryConfig;
2626
private apiConfig!: TelemetryApi;
27+
private metadata!: TelemetryConfigMetadata;
2728

2829
public constructor() {
2930
this.initialize();
@@ -54,6 +55,11 @@ export class TelemetryConfiguration {
5455
baseEndpoint: config.telemetryApi.baseEndpoint,
5556
version: config.telemetryApi.version
5657
});
58+
59+
this.metadata = Object.freeze({
60+
consentSchemaVersion: config.metadata.consentSchemaVersion
61+
});
62+
5763
} catch (error: any) {
5864
LOGGER.error("Error occurred while setting up telemetry config");
5965
LOGGER.error(error.message);
@@ -68,4 +74,7 @@ export class TelemetryConfiguration {
6874
return this.apiConfig;
6975
}
7076

77+
public getTelemetryConfigMetadata(): Readonly<TelemetryConfigMetadata> {
78+
return this.metadata;
79+
}
7180
}

vscode/src/telemetry/constants.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Copyright (c) 2024-2025, Oracle and/or its affiliates.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
export const TELEMETRY_CONSENT_VERSION_SCHEMA_KEY = "telemetryConsentSchemaVersion";
17+
export const TELEMETRY_CONSENT_RESPONSE_TIME_KEY = "telemetryConsentResponseTime";
18+
export const TELEMETRY_SETTING_VALUE_KEY = "telemetrySettingValue";

vscode/src/telemetry/events/baseEvent.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2024, Oracle and/or its affiliates.
2+
Copyright (c) 2024-2025, Oracle and/or its affiliates.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -42,7 +42,7 @@ export abstract class BaseEvent<T> {
4242
get getPayload(): T & BaseEventPayload {
4343
return this._payload;
4444
}
45-
45+
4646
get getData(): T {
4747
return this._data;
4848
}
@@ -58,8 +58,8 @@ export abstract class BaseEvent<T> {
5858
protected addEventToCache = (): void => {
5959
const dataString = JSON.stringify(this.getData);
6060
const calculatedHashVal = getHashCode(dataString);
61-
const isAdded = cacheService.put(this.NAME, calculatedHashVal);
62-
63-
LOGGER.debug(`${this.NAME} added in cache ${isAdded ? "Successfully" : "Unsucessfully"}`);
61+
cacheService.put(this.NAME, calculatedHashVal).then((isAdded: boolean) => {
62+
LOGGER.debug(`${this.NAME} added in cache ${isAdded ? "Successfully" : "Unsucessfully"}`);
63+
});
6464
}
6565
}

vscode/src/telemetry/events/close.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2024, Oracle and/or its affiliates.
2+
Copyright (c) 2024-2025, Oracle and/or its affiliates.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

vscode/src/telemetry/events/jdkDownload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2024, Oracle and/or its affiliates.
2+
Copyright (c) 2024-2025, Oracle and/or its affiliates.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

vscode/src/telemetry/events/jdkFeature.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2024, Oracle and/or its affiliates.
2+
Copyright (c) 2024-2025, Oracle and/or its affiliates.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

vscode/src/telemetry/events/start.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2024, Oracle and/or its affiliates.
2+
Copyright (c) 2024-2025, Oracle and/or its affiliates.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

vscode/src/telemetry/events/workspaceChange.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2024, Oracle and/or its affiliates.
2+
Copyright (c) 2024-2025, Oracle and/or its affiliates.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

vscode/src/telemetry/impl/AnonymousIdManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2024, Oracle and/or its affiliates.
2+
Copyright (c) 2024-2025, Oracle and/or its affiliates.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

vscode/src/telemetry/impl/cacheServiceImpl.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2024, Oracle and/or its affiliates.
2+
Copyright (c) 2024-2025, Oracle and/or its affiliates.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -28,10 +28,11 @@ class CacheServiceImpl implements CacheService {
2828
}
2929
}
3030

31-
public put = (key: string, value: string): boolean => {
31+
public put = async (key: string, value: string): Promise<boolean> => {
3232
try {
3333
const vscGlobalState = globalState.getExtensionContextInfo().getVscGlobalState();
34-
vscGlobalState.update(key, value);
34+
await vscGlobalState.update(key, value);
35+
LOGGER.debug(`Updating key: ${key} to ${value}`);
3536
return true;
3637
} catch (err) {
3738
LOGGER.error(`Error while storing ${key} in cache: ${(err as Error).message}`);

vscode/src/telemetry/impl/enviromentDetails.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2024, Oracle and/or its affiliates.
2+
Copyright (c) 2024-2025, Oracle and/or its affiliates.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

vscode/src/telemetry/impl/postTelemetry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2024, Oracle and/or its affiliates.
2+
Copyright (c) 2024-2025, Oracle and/or its affiliates.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

vscode/src/telemetry/impl/telemetryEventQueue.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2024, Oracle and/or its affiliates.
2+
Copyright (c) 2024-2025, Oracle and/or its affiliates.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -13,9 +13,10 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16+
import { LOGGER } from "../../logger";
1617
import { BaseEvent } from "../events/baseEvent";
1718

18-
export class TelemetryEventQueue {
19+
export class TelemetryEventQueue {
1920
private events: BaseEvent<any>[] = [];
2021

2122
public enqueue = (e: BaseEvent<any>): void => {
@@ -35,4 +36,26 @@ export class TelemetryEventQueue {
3536
this.events = [];
3637
return queue;
3738
}
39+
40+
public adjustQueueSize = (maxNumOfEventsToRetain: number) => {
41+
const excess = this.size() - maxNumOfEventsToRetain;
42+
43+
if (excess > 0) {
44+
LOGGER.debug('Decreasing size of the queue as max capacity reached');
45+
46+
const seen = new Set<string>();
47+
const deduplicated = [];
48+
49+
for (let i = 0; i < excess; i++) {
50+
const event = this.events[i];
51+
if (!seen.has(event.NAME)) {
52+
deduplicated.push(event);
53+
seen.add(event.NAME);
54+
}
55+
}
56+
57+
this.events = [...deduplicated, ...this.events.slice(excess)];
58+
}
59+
}
60+
3861
}

0 commit comments

Comments
 (0)