Skip to content

Commit

Permalink
Fix ability to recognize extensions which access environment API (#20791
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
Kartik Raj authored Mar 3, 2023
1 parent ee8e80e commit e8303bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/client/proposedApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,16 @@ export function buildProposedApi(
const extensions = serviceContainer.get<IExtensions>(IExtensions);
const envVarsProvider = serviceContainer.get<IEnvironmentVariablesProvider>(IEnvironmentVariablesProvider);
function sendApiTelemetry(apiName: string, args?: unknown) {
setTimeout(() =>
extensions
.determineExtensionFromCallStack()
.then((info) => {
sendTelemetryEvent(EventName.PYTHON_ENVIRONMENTS_API, undefined, {
apiName,
extensionId: info.extensionId,
});
traceVerbose(
`Extension ${info.extensionId} accessed ${apiName} with args: ${JSON.stringify(args)}`,
);
})
.ignoreErrors(),
);
extensions
.determineExtensionFromCallStack()
.then((info) => {
sendTelemetryEvent(EventName.PYTHON_ENVIRONMENTS_API, undefined, {
apiName,
extensionId: info.extensionId,
});
traceVerbose(`Extension ${info.extensionId} accessed ${apiName} with args: ${JSON.stringify(args)}`);
})
.ignoreErrors();
}
disposables.push(
discoveryApi.onChanged((e) => {
Expand Down
2 changes: 2 additions & 0 deletions src/test/proposedApi.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ suite('Proposed Extension API', () => {
});

teardown(() => {
// Verify each API method sends telemetry regarding who called the API.
extensions.verifyAll();
sinon.restore();
});

Expand Down

0 comments on commit e8303bb

Please sign in to comment.