Skip to content
Open
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
25 changes: 25 additions & 0 deletions src/common/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ export enum EventNames {
* - hasPersistedSelection: boolean (whether a persisted env path existed in workspace state)
*/
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)
*/
ENV_SELECTION_COMPLETED = 'ENV_SELECTION.COMPLETED',
/**
* Telemetry event fired when a lazily-registered manager completes its first initialization.
* Replaces MANAGER_REGISTRATION_SKIPPED and MANAGER_REGISTRATION_FAILED for managers
Expand Down Expand Up @@ -395,6 +405,21 @@ export interface IEventNamePropertyMapping {
hasPersistedSelection: boolean;
};

/* __GDPR__
"env_selection.completed": {
"globalScopeDeferred": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "owner": "eleanorjboyd" },
"workspaceFolderCount": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "owner": "eleanorjboyd" },
"resolvedFolderCount": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "owner": "eleanorjboyd" },
"settingErrorCount": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "owner": "eleanorjboyd" }
}
*/
[EventNames.ENV_SELECTION_COMPLETED]: {
globalScopeDeferred: boolean;
workspaceFolderCount: number;
resolvedFolderCount: number;
settingErrorCount: number;
};
Comment thread
eleanorjboyd marked this conversation as resolved.

/* __GDPR__
"manager.lazy_init": {
"managerName": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "owner": "eleanorjboyd" },
Expand Down
90 changes: 62 additions & 28 deletions src/features/interpreterSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,16 @@ export async function applyInitialEnvironmentSelection(
`[interpreterSelection] Applying initial environment selection for ${folders.length} workspace folder(s)`,
);

// Checkpoint 1: env selection starting — managers are registered
sendTelemetryEvent(EventNames.ENV_SELECTION_STARTED, activationToReadyDurationMs, {
registeredManagerCount: envManagers.managers.length,
registeredManagerIds: envManagers.managers.map((m) => m.id).join(','),
workspaceFolderCount: folders.length,
});

const allErrors: SettingResolutionError[] = [];
let workspaceFolderResolved = false;
let resolvedFolderCount = 0;
const selectionStopWatch = new StopWatch();

for (const folder of folders) {
try {
Expand All @@ -311,23 +313,24 @@ export async function applyInitialEnvironmentSelection(
);
allErrors.push(...errors);

// Checkpoint 2: priority chain resolved — which path?
const isPathA = result.environment !== undefined;

// Get the specific environment if not already resolved
const env = result.environment ?? (await result.manager.get(folder.uri));

sendTelemetryEvent(EventNames.ENV_SELECTION_RESULT, scopeStopWatch.elapsedTime, {
scope: 'workspace',
prioritySource: result.source,
managerId: result.manager.id,
resolutionPath: isPathA ? 'envPreResolved' : 'managerDiscovery',
resolutionPath: result.environment ? 'envPreResolved' : 'managerDiscovery',
hasPersistedSelection: env !== undefined,
});

// Cache only — NO settings.json write (shouldPersistSettings = false)
await envManagers.setEnvironment(folder.uri, env, false);

if (env) {
workspaceFolderResolved = true;
resolvedFolderCount++;
}

traceInfo(
`[interpreterSelection] ${folder.name}: ${env?.displayName ?? 'none'} (source: ${result.source})`,
);
Expand All @@ -336,38 +339,69 @@ export async function applyInitialEnvironmentSelection(
}
}

// Also apply initial selection for global scope (no workspace folder)
// This ensures defaultInterpreterPath is respected even without a workspace
try {
const globalStopWatch = new StopWatch();
const { result, errors } = await resolvePriorityChainCore(undefined, envManagers, undefined, nativeFinder, api);
allErrors.push(...errors);
// Resolve global scope (fallback for files outside workspace folders).
// Deferred to background when a workspace folder already resolved.
const resolveGlobalScope = async (): Promise<SettingResolutionError[]> => {
try {
const globalStopWatch = new StopWatch();
const { result, errors: globalErrors } = await resolvePriorityChainCore(
undefined,
envManagers,
undefined,
nativeFinder,
api,
);

const isPathA = result.environment !== undefined;
const env = result.environment ?? (await result.manager.get(undefined));

// Get the specific environment if not already resolved
const env = result.environment ?? (await result.manager.get(undefined));
sendTelemetryEvent(EventNames.ENV_SELECTION_RESULT, globalStopWatch.elapsedTime, {
scope: 'global',
prioritySource: result.source,
managerId: result.manager.id,
resolutionPath: result.environment ? 'envPreResolved' : 'managerDiscovery',
hasPersistedSelection: env !== undefined,
});

sendTelemetryEvent(EventNames.ENV_SELECTION_RESULT, globalStopWatch.elapsedTime, {
scope: 'global',
prioritySource: result.source,
managerId: result.manager.id,
resolutionPath: isPathA ? 'envPreResolved' : 'managerDiscovery',
hasPersistedSelection: env !== undefined,
});
// Cache only — NO settings.json write
await envManagers.setEnvironments('global', env, false);

// Cache only — NO settings.json write (shouldPersistSettings = false)
await envManagers.setEnvironments('global', env, false);
traceInfo(`[interpreterSelection] global: ${env?.displayName ?? 'none'} (source: ${result.source})`);

traceInfo(`[interpreterSelection] global: ${env?.displayName ?? 'none'} (source: ${result.source})`);
} catch (err) {
traceError(`[interpreterSelection] Failed to set global environment: ${err}`);
return globalErrors;
} catch (err) {
traceError(`[interpreterSelection] Failed to set global environment: ${err}`);
return [];
}
};

if (workspaceFolderResolved) {
// Defer global scope so it doesn't block post-selection startup.
traceInfo('[interpreterSelection] Workspace env resolved, deferring global scope to background');
resolveGlobalScope()
.then(async (globalErrors) => {
if (globalErrors.length > 0) {
await notifyUserOfSettingErrors(globalErrors);
}
})
.catch((err) => traceError(`[interpreterSelection] Background global scope resolution failed: ${err}`));
} else {
// No workspace folder resolved — global scope is the primary fallback, must await.
const globalErrors = await resolveGlobalScope();
allErrors.push(...globalErrors);
}

// Notify user if any settings could not be applied
// Notify user if any settings could not be applied (workspace + global when awaited)
if (allErrors.length > 0) {
await notifyUserOfSettingErrors(allErrors);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be producing duplicate dialogs as the await notifyUserOfSettingErrors(globalErrors) at the same time?

}

// 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,
});
}

/**
Expand Down
Loading
Loading