Skip to content

Commit ba94553

Browse files
author
Kartik Raj
authored
Modify telemetry to contain trigger time as property (#22941)
1 parent 178a0b2 commit ba94553

File tree

6 files changed

+31
-11
lines changed

6 files changed

+31
-11
lines changed

src/client/common/persistentState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class PersistentState<T> implements IPersistentState<T> {
108108
export const GLOBAL_PERSISTENT_KEYS_DEPRECATED = 'PYTHON_EXTENSION_GLOBAL_STORAGE_KEYS';
109109
export const WORKSPACE_PERSISTENT_KEYS_DEPRECATED = 'PYTHON_EXTENSION_WORKSPACE_STORAGE_KEYS';
110110

111-
const GLOBAL_PERSISTENT_KEYS = 'PYTHON_GLOBAL_STORAGE_KEYS';
111+
export const GLOBAL_PERSISTENT_KEYS = 'PYTHON_GLOBAL_STORAGE_KEYS';
112112
const WORKSPACE_PERSISTENT_KEYS = 'PYTHON_WORKSPACE_STORAGE_KEYS';
113113
type KeysStorageType = 'global' | 'workspace';
114114
export type KeysStorage = { key: string; defaultValue: unknown };

src/client/extension.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import { WorkspaceService } from './common/application/workspace';
4646
import { disposeAll } from './common/utils/resourceLifecycle';
4747
import { ProposedExtensionAPI } from './proposedApiTypes';
4848
import { buildProposedApi } from './proposedApi';
49+
import { GLOBAL_PERSISTENT_KEYS } from './common/persistentState';
4950

5051
durations.codeLoadingTime = stopWatch.elapsedTime;
5152

@@ -62,7 +63,9 @@ export async function activate(context: IExtensionContext): Promise<PythonExtens
6263
let api: PythonExtension;
6364
let ready: Promise<void>;
6465
let serviceContainer: IServiceContainer;
66+
let isFirstSession: boolean | undefined;
6567
try {
68+
isFirstSession = context.globalState.get(GLOBAL_PERSISTENT_KEYS, []).length === 0;
6669
const workspaceService = new WorkspaceService();
6770
context.subscriptions.push(
6871
workspaceService.onDidGrantWorkspaceTrust(async () => {
@@ -79,8 +82,7 @@ export async function activate(context: IExtensionContext): Promise<PythonExtens
7982
}
8083
// Send the "success" telemetry only if activation did not fail.
8184
// Otherwise Telemetry is send via the error handler.
82-
83-
sendStartupTelemetry(ready, durations, stopWatch, serviceContainer)
85+
sendStartupTelemetry(ready, durations, stopWatch, serviceContainer, isFirstSession)
8486
// Run in the background.
8587
.ignoreErrors();
8688
return api;

src/client/languageServer/watcher.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ export class LanguageServerWatcher implements IExtensionActivationService, ILang
178178
// Start the language server.
179179
if (startupStopWatch) {
180180
// It means that startup is triggering this code, track time it takes since startup to activate this code.
181-
sendTelemetryEvent(EventName.LANGUAGE_SERVER_TRIGGER_DURATION, startupStopWatch.elapsedTime);
181+
sendTelemetryEvent(EventName.LANGUAGE_SERVER_TRIGGER_TIME, startupStopWatch.elapsedTime, {
182+
triggerTime: startupStopWatch.elapsedTime,
183+
});
182184
}
183185
await languageServerExtensionManager.startLanguageServer(lsResource, interpreter);
184186

src/client/startupTelemetry.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export async function sendStartupTelemetry(
2222
durations: IStartupDurations,
2323
stopWatch: IStopWatch,
2424
serviceContainer: IServiceContainer,
25+
isFirstSession: boolean,
2526
) {
2627
if (isTestExecution()) {
2728
return;
@@ -30,7 +31,7 @@ export async function sendStartupTelemetry(
3031
try {
3132
await activatedPromise;
3233
durations.totalNonBlockingActivateTime = stopWatch.elapsedTime - durations.startActivateTime;
33-
const props = await getActivationTelemetryProps(serviceContainer);
34+
const props = await getActivationTelemetryProps(serviceContainer, isFirstSession);
3435
sendTelemetryEvent(EventName.EDITOR_LOAD, durations, props);
3536
} catch (ex) {
3637
traceError('sendStartupTelemetry() failed.', ex);
@@ -76,7 +77,10 @@ export function hasUserDefinedPythonPath(resource: Resource, serviceContainer: I
7677
: false;
7778
}
7879

79-
async function getActivationTelemetryProps(serviceContainer: IServiceContainer): Promise<EditorLoadTelemetry> {
80+
async function getActivationTelemetryProps(
81+
serviceContainer: IServiceContainer,
82+
isFirstSession?: boolean,
83+
): Promise<EditorLoadTelemetry> {
8084
// TODO: Not all of this data is showing up in the database...
8185

8286
// TODO: If any one of these parts fails we send no info. We should
@@ -88,7 +92,7 @@ async function getActivationTelemetryProps(serviceContainer: IServiceContainer):
8892
const terminalHelper = serviceContainer.get<ITerminalHelper>(ITerminalHelper);
8993
const terminalShellType = terminalHelper.identifyTerminalShell();
9094
if (!workspaceService.isTrusted) {
91-
return { workspaceFolderCount, terminal: terminalShellType };
95+
return { workspaceFolderCount, terminal: terminalShellType, isFirstSession };
9296
}
9397
const interpreterService = serviceContainer.get<IInterpreterService>(IInterpreterService);
9498
const mainWorkspaceUri = workspaceService.workspaceFolders?.length
@@ -132,5 +136,6 @@ async function getActivationTelemetryProps(serviceContainer: IServiceContainer):
132136
usingUserDefinedInterpreter,
133137
usingGlobalInterpreter,
134138
appName,
139+
isFirstSession,
135140
};
136141
}

src/client/telemetry/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export enum EventName {
6464
EXTENSION_SURVEY_PROMPT = 'EXTENSION_SURVEY_PROMPT',
6565

6666
LANGUAGE_SERVER_ENABLED = 'LANGUAGE_SERVER.ENABLED',
67-
LANGUAGE_SERVER_TRIGGER_DURATION = 'LANGUAGE_SERVER.TRIGGER_DURATION',
67+
LANGUAGE_SERVER_TRIGGER_TIME = 'LANGUAGE_SERVER_TRIGGER_TIME',
6868
LANGUAGE_SERVER_STARTUP = 'LANGUAGE_SERVER.STARTUP',
6969
LANGUAGE_SERVER_READY = 'LANGUAGE_SERVER.READY',
7070
LANGUAGE_SERVER_TELEMETRY = 'LANGUAGE_SERVER.EVENT',

src/client/telemetry/index.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,11 @@ export interface IEventNamePropertyMapping {
723723
* If global interpreter is being used
724724
*/
725725
usingGlobalInterpreter?: boolean;
726+
/**
727+
* Carries `true` if it is the very first session of the user. We check whether persistent cache is empty
728+
* to approximately guess if it's the first session.
729+
*/
730+
isFirstSession?: boolean;
726731
};
727732
/**
728733
* Telemetry event sent when substituting Environment variables to calculate value of variables
@@ -1329,11 +1334,17 @@ export interface IEventNamePropertyMapping {
13291334
* Track how long it takes to trigger language server activation code, after Python extension starts activating.
13301335
*/
13311336
/* __GDPR__
1332-
"language_server_trigger_duration" : {
1333-
"duration" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "owner": "karrtikr", "isMeasurement": true }
1337+
"language_server_trigger_time" : {
1338+
"duration" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "owner": "karrtikr" },
1339+
"triggerTime" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "owner": "karrtikr" }
13341340
}
13351341
*/
1336-
[EventName.LANGUAGE_SERVER_TRIGGER_DURATION]: unknown;
1342+
[EventName.LANGUAGE_SERVER_TRIGGER_TIME]: {
1343+
/**
1344+
* Time it took to trigger language server startup.
1345+
*/
1346+
triggerTime: number;
1347+
};
13371348
/**
13381349
* Telemetry event sent when starting Node.js server
13391350
*/

0 commit comments

Comments
 (0)