Skip to content
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
17 changes: 8 additions & 9 deletions src/common/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export enum EventNames {
* the timer is cancelled and this event never fires.
* Properties:
* - failureStage: string (which phase was in progress when the watchdog fired)
* Measures:
* - duration: total elapsed since activation
* - stageDuration: elapsed in the current stage
*/
SETUP_HANG_DETECTED = 'SETUP.HANG_DETECTED',
/**
Expand Down Expand Up @@ -103,12 +106,10 @@ export enum EventNames {
ENV_SELECTION_RESULT = 'ENV_SELECTION.RESULT',
/**
* Telemetry event fired when applyInitialEnvironmentSelection returns.
* Duration measures the blocking time (excludes deferred global scope).
* Properties:
* - globalScopeDeferred: boolean (true = global scope fired in background, false = awaited)
* - workspaceFolderCount: number (total workspace folders)
* - resolvedFolderCount: number (folders that resolved with a non-undefined env)
* - settingErrorCount: number (user-configured settings that could not be applied)
* - globalScopeDeferred: boolean (true = global scope fired in background)
* Measures:
* - duration, workspaceFolderCount, resolvedFolderCount, settingErrorCount
*/
ENV_SELECTION_COMPLETED = 'ENV_SELECTION.COMPLETED',
/**
Expand Down Expand Up @@ -381,7 +382,8 @@ export interface IEventNamePropertyMapping {
/* __GDPR__
"setup.hang_detected": {
"failureStage": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "owner": "StellaHuang95" },
"<duration>": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "owner": "StellaHuang95" }
"<duration>": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "owner": "eleanorjboyd" },
"<stageDuration>": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "owner": "eleanorjboyd" }
}
*/
[EventNames.SETUP_HANG_DETECTED]: {
Expand Down Expand Up @@ -451,9 +453,6 @@ export interface IEventNamePropertyMapping {
*/
[EventNames.ENV_SELECTION_COMPLETED]: {
globalScopeDeferred: boolean;
workspaceFolderCount: number;
resolvedFolderCount: number;
settingErrorCount: number;
};

/* __GDPR__
Expand Down
11 changes: 10 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
*/
setImmediate(async () => {
let failureStage = 'nativeFinder';
const stageWatch = new StopWatch();
// Watchdog: fires if setup hasn't completed within 120s, indicating a likely hang
const SETUP_HANG_TIMEOUT_MS = 120_000;
let hangWatchdogActive = true;
Expand All @@ -568,7 +569,11 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
}
hangWatchdogActive = false;
traceError(`Setup appears hung during stage: ${failureStage}`);
sendTelemetryEvent(EventNames.SETUP_HANG_DETECTED, start.elapsedTime, { failureStage });
sendTelemetryEvent(
EventNames.SETUP_HANG_DETECTED,
{ duration: start.elapsedTime, stageDuration: stageWatch.elapsedTime },
{ failureStage },
);
}, SETUP_HANG_TIMEOUT_MS);
context.subscriptions.push({ dispose: clearHangWatchdog });
try {
Expand All @@ -592,6 +597,7 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
sysPythonManager.resolve(sysMgr);
// Each manager registers independently — one failure must not block the others.
failureStage = 'managerRegistration';
stageWatch.reset();
await Promise.all([
safeRegister(
'system',
Expand All @@ -611,14 +617,17 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
]);

failureStage = 'envSelection';
stageWatch.reset();
await applyInitialEnvironmentSelection(envManagers, projectManager, nativeFinder, api, start.elapsedTime);

// Register manager-agnostic terminal watcher for package-modifying commands
failureStage = 'terminalWatcher';
stageWatch.reset();
registerTerminalPackageWatcher(api, terminalActivation, outputChannel, context.subscriptions);

// Register listener for interpreter settings changes for interpreter re-selection
failureStage = 'settingsListener';
stageWatch.reset();
context.subscriptions.push(
registerInterpreterSettingsChangeListener(envManagers, projectManager, nativeFinder, api),
);
Expand Down
20 changes: 13 additions & 7 deletions src/features/interpreterSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,19 @@ export async function applyInitialEnvironmentSelection(
await notifyUserOfSettingErrors(allErrors);
}

// Duration measures blocking time only (excludes deferred global scope).
sendTelemetryEvent(EventNames.ENV_SELECTION_COMPLETED, selectionStopWatch.elapsedTime, {
globalScopeDeferred: workspaceFolderResolved,
workspaceFolderCount: folders.length,
resolvedFolderCount,
settingErrorCount: allErrors.length,
});
// Numeric values must go via the measures argument (properties are dropped).
sendTelemetryEvent(
EventNames.ENV_SELECTION_COMPLETED,
{
duration: selectionStopWatch.elapsedTime,
workspaceFolderCount: folders.length,
resolvedFolderCount,
settingErrorCount: allErrors.length,
},
{
globalScopeDeferred: workspaceFolderResolved,
},
);
}

/**
Expand Down
Loading