Skip to content

Commit e8303bb

Browse files
author
Kartik Raj
authored
Fix ability to recognize extensions which access environment API (#20791)
Follow up from #20222. Apparently `setTimeout` changed the stack in such a way that we were unable to recognize which extension called the API: ``` [DEBUG 2023-2-2 16:21:9.641]: Extension unknown accessed getActiveEnvironmentPath with args: undefined ``` Reverting the change.
1 parent ee8e80e commit e8303bb

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/client/proposedApi.ts

+10-14
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,16 @@ export function buildProposedApi(
125125
const extensions = serviceContainer.get<IExtensions>(IExtensions);
126126
const envVarsProvider = serviceContainer.get<IEnvironmentVariablesProvider>(IEnvironmentVariablesProvider);
127127
function sendApiTelemetry(apiName: string, args?: unknown) {
128-
setTimeout(() =>
129-
extensions
130-
.determineExtensionFromCallStack()
131-
.then((info) => {
132-
sendTelemetryEvent(EventName.PYTHON_ENVIRONMENTS_API, undefined, {
133-
apiName,
134-
extensionId: info.extensionId,
135-
});
136-
traceVerbose(
137-
`Extension ${info.extensionId} accessed ${apiName} with args: ${JSON.stringify(args)}`,
138-
);
139-
})
140-
.ignoreErrors(),
141-
);
128+
extensions
129+
.determineExtensionFromCallStack()
130+
.then((info) => {
131+
sendTelemetryEvent(EventName.PYTHON_ENVIRONMENTS_API, undefined, {
132+
apiName,
133+
extensionId: info.extensionId,
134+
});
135+
traceVerbose(`Extension ${info.extensionId} accessed ${apiName} with args: ${JSON.stringify(args)}`);
136+
})
137+
.ignoreErrors();
142138
}
143139
disposables.push(
144140
discoveryApi.onChanged((e) => {

src/test/proposedApi.unit.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ suite('Proposed Extension API', () => {
9999
});
100100

101101
teardown(() => {
102+
// Verify each API method sends telemetry regarding who called the API.
103+
extensions.verifyAll();
102104
sinon.restore();
103105
});
104106

0 commit comments

Comments
 (0)