Skip to content

Commit 23c96ed

Browse files
committed
catch exception
1 parent afd135a commit 23c96ed

1 file changed

Lines changed: 39 additions & 31 deletions

File tree

src/common/telemetry/helpers.ts

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getDefaultEnvManagerSetting, getDefaultPkgManagerSetting } from '../../features/settings/settingHelpers';
22
import { EnvironmentManagers, PythonProjectManager } from '../../internal.api';
33
import { getUvEnvironments } from '../../managers/builtin/uvEnvironments';
4+
import { traceVerbose } from '../logging';
45
import { getWorkspaceFolders } from '../workspace.apis';
56
import { EventNames } from './constants';
67
import { sendTelemetryEvent } from './sender';
@@ -106,43 +107,50 @@ export async function sendEnvironmentToolUsageTelemetry(
106107
pm: PythonProjectManager,
107108
envManagers: EnvironmentManagers,
108109
): Promise<void> {
109-
const projects = pm.getProjects();
110-
111-
// Track which tools are used (Set ensures uniqueness)
112-
const toolsUsed = new Set<string>();
110+
try {
111+
const projects = pm.getProjects();
112+
113+
// Track which tools are used (Set ensures uniqueness)
114+
const toolsUsed = new Set<string>();
115+
116+
// Lazily loaded once when a venv environment is first encountered
117+
let uvEnvPaths: string[] | undefined;
118+
119+
// Check which environment manager is used for each project
120+
for (const project of projects) {
121+
try {
122+
const env = await envManagers.getEnvironment(project.uri);
123+
if (env?.envId?.managerId) {
124+
let toolName = extractToolName(env.envId.managerId);
125+
126+
// UV environments share the venv manager. Check the persistent UV env list instead
127+
if (toolName === 'venv' && env.environmentPath) {
128+
uvEnvPaths ??= await getUvEnvironments();
129+
if (uvEnvPaths.includes(env.environmentPath.fsPath)) {
130+
toolName = 'uv';
131+
}
132+
}
113133

114-
// Check which environment manager is used for each project
115-
for (const project of projects) {
116-
try {
117-
const env = await envManagers.getEnvironment(project.uri);
118-
if (env?.envId?.managerId) {
119-
let toolName = extractToolName(env.envId.managerId);
120-
121-
// UV environments share the venv manager. Check the persistent UV env list instead
122-
if (toolName === 'venv' && env.environmentPath) {
123-
// Lazily load UV environment paths only when a venv environment is encountered
124-
const uvEnvPaths = await getUvEnvironments();
125-
if (uvEnvPaths.includes(env.environmentPath.fsPath)) {
126-
toolName = 'uv';
134+
// Normalize 'global' to 'system' for consistency
135+
if (toolName === 'global') {
136+
toolName = 'system';
127137
}
128-
}
129138

130-
// Normalize 'global' to 'system' for consistency
131-
if (toolName === 'global') {
132-
toolName = 'system';
139+
toolsUsed.add(toolName);
133140
}
134-
135-
toolsUsed.add(toolName);
141+
} catch {
142+
// Ignore errors when getting environment for a project
136143
}
137-
} catch {
138-
// Ignore errors when getting environment for a project
139144
}
140-
}
141145

142-
// Fire one event per tool used
143-
toolsUsed.forEach((tool) => {
144-
sendTelemetryEvent(EventNames.ENVIRONMENT_TOOL_USAGE, undefined, {
145-
toolName: tool,
146+
// Fire one event per tool used
147+
toolsUsed.forEach((tool) => {
148+
sendTelemetryEvent(EventNames.ENVIRONMENT_TOOL_USAGE, undefined, {
149+
toolName: tool,
150+
});
146151
});
147-
});
152+
} catch (error) {
153+
// Telemetry failures must never disrupt extension activation
154+
traceVerbose('Failed to send environment tool usage telemetry:', error);
155+
}
148156
}

0 commit comments

Comments
 (0)