Skip to content

Enhancement in telemetry preferences flow and some telemetry maintenance changes #403

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

Merged
merged 5 commits into from
Apr 24, 2025
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
6 changes: 6 additions & 0 deletions vscode/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ const createTelemetryConfig = () => {
baseUrl: null,
baseEndpoint: "/vscode/java/sendTelemetry",
version: "/v1"
},
metadata: {
consentSchemaVersion: "v1"
}
}

Expand All @@ -73,6 +76,9 @@ const createTelemetryConfig = () => {
baseUrl: process.env.TELEMETRY_API_BASE_URL,
baseEndpoint: process.env.TELEMETRY_API_ENDPOINT,
version: process.env.TELEMETRY_API_VERSION
},
metadata: {
consentSchemaVersion: process.env.CONSENT_SCHEMA_VERSION
}
});

Expand Down
5 changes: 4 additions & 1 deletion vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@
"jdk.telemetry.enabled": {
"type": "boolean",
"description": "%jdk.configuration.telemetry.enabled.description%",
"default": false
"default": false,
"tags": [
"telemetry"
]
}
}
},
Expand Down
13 changes: 11 additions & 2 deletions vscode/src/telemetry/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2024, Oracle and/or its affiliates.
Copyright (c) 2024-2025, Oracle and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -13,7 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
import { RetryConfig, TelemetryApi } from "./types";
import { RetryConfig, TelemetryApi, TelemetryConfigMetadata } from "./types";
import * as path from 'path';
import * as fs from 'fs';
import { LOGGER } from "../logger";
Expand All @@ -24,6 +24,7 @@ export class TelemetryConfiguration {
private static instance: TelemetryConfiguration;
private retryConfig!: RetryConfig;
private apiConfig!: TelemetryApi;
private metadata!: TelemetryConfigMetadata;

public constructor() {
this.initialize();
Expand Down Expand Up @@ -54,6 +55,11 @@ export class TelemetryConfiguration {
baseEndpoint: config.telemetryApi.baseEndpoint,
version: config.telemetryApi.version
});

this.metadata = Object.freeze({
consentSchemaVersion: config.metadata.consentSchemaVersion
});

} catch (error: any) {
LOGGER.error("Error occurred while setting up telemetry config");
LOGGER.error(error.message);
Expand All @@ -68,4 +74,7 @@ export class TelemetryConfiguration {
return this.apiConfig;
}

public getTelemetryConfigMetadata(): Readonly<TelemetryConfigMetadata> {
return this.metadata;
}
}
18 changes: 18 additions & 0 deletions vscode/src/telemetry/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Copyright (c) 2024-2025, Oracle and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
export const TELEMETRY_CONSENT_VERSION_SCHEMA_KEY = "telemetryConsentSchemaVersion";
export const TELEMETRY_CONSENT_RESPONSE_TIME_KEY = "telemetryConsentResponseTime";
export const TELEMETRY_SETTING_VALUE_KEY = "telemetrySettingValue";
10 changes: 5 additions & 5 deletions vscode/src/telemetry/events/baseEvent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2024, Oracle and/or its affiliates.
Copyright (c) 2024-2025, Oracle and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,7 +42,7 @@ export abstract class BaseEvent<T> {
get getPayload(): T & BaseEventPayload {
return this._payload;
}

get getData(): T {
return this._data;
}
Expand All @@ -58,8 +58,8 @@ export abstract class BaseEvent<T> {
protected addEventToCache = (): void => {
const dataString = JSON.stringify(this.getData);
const calculatedHashVal = getHashCode(dataString);
const isAdded = cacheService.put(this.NAME, calculatedHashVal);

LOGGER.debug(`${this.NAME} added in cache ${isAdded ? "Successfully" : "Unsucessfully"}`);
cacheService.put(this.NAME, calculatedHashVal).then((isAdded: boolean) => {
LOGGER.debug(`${this.NAME} added in cache ${isAdded ? "Successfully" : "Unsucessfully"}`);
});
}
}
2 changes: 1 addition & 1 deletion vscode/src/telemetry/events/close.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2024, Oracle and/or its affiliates.
Copyright (c) 2024-2025, Oracle and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/telemetry/events/jdkDownload.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2024, Oracle and/or its affiliates.
Copyright (c) 2024-2025, Oracle and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/telemetry/events/jdkFeature.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2024, Oracle and/or its affiliates.
Copyright (c) 2024-2025, Oracle and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/telemetry/events/start.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2024, Oracle and/or its affiliates.
Copyright (c) 2024-2025, Oracle and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/telemetry/events/workspaceChange.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2024, Oracle and/or its affiliates.
Copyright (c) 2024-2025, Oracle and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/telemetry/impl/AnonymousIdManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2024, Oracle and/or its affiliates.
Copyright (c) 2024-2025, Oracle and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
7 changes: 4 additions & 3 deletions vscode/src/telemetry/impl/cacheServiceImpl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2024, Oracle and/or its affiliates.
Copyright (c) 2024-2025, Oracle and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,10 +28,11 @@ class CacheServiceImpl implements CacheService {
}
}

public put = (key: string, value: string): boolean => {
public put = async (key: string, value: string): Promise<boolean> => {
try {
const vscGlobalState = globalState.getExtensionContextInfo().getVscGlobalState();
vscGlobalState.update(key, value);
await vscGlobalState.update(key, value);
LOGGER.debug(`Updating key: ${key} to ${value}`);
return true;
} catch (err) {
LOGGER.error(`Error while storing ${key} in cache: ${(err as Error).message}`);
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/telemetry/impl/enviromentDetails.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2024, Oracle and/or its affiliates.
Copyright (c) 2024-2025, Oracle and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/telemetry/impl/postTelemetry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2024, Oracle and/or its affiliates.
Copyright (c) 2024-2025, Oracle and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
27 changes: 25 additions & 2 deletions vscode/src/telemetry/impl/telemetryEventQueue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2024, Oracle and/or its affiliates.
Copyright (c) 2024-2025, Oracle and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -13,9 +13,10 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
import { LOGGER } from "../../logger";
import { BaseEvent } from "../events/baseEvent";

export class TelemetryEventQueue {
export class TelemetryEventQueue {
private events: BaseEvent<any>[] = [];

public enqueue = (e: BaseEvent<any>): void => {
Expand All @@ -35,4 +36,26 @@ export class TelemetryEventQueue {
this.events = [];
return queue;
}

public adjustQueueSize = (maxNumOfEventsToRetain: number) => {
const excess = this.size() - maxNumOfEventsToRetain;

if (excess > 0) {
LOGGER.debug('Decreasing size of the queue as max capacity reached');

const seen = new Set<string>();
const deduplicated = [];

for (let i = 0; i < excess; i++) {
const event = this.events[i];
if (!seen.has(event.NAME)) {
deduplicated.push(event);
seen.add(event.NAME);
}
}

this.events = [...deduplicated, ...this.events.slice(excess)];
}
}

}
Loading