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
24 changes: 8 additions & 16 deletions src/client/telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2209,14 +2209,10 @@ export interface IEventNamePropertyMapping {
| 'env-resolution'
| 'cancelled'
| 'unknown';
/**
* Wall-clock duration of the discovery cycle in milliseconds.
*/
totalDurationMs?: number;
/**
* Number of test items discovered (leaf nodes).
*/
testCount?: number;
// NOTE: `totalDurationMs` and `testCount` are measurements (see the __GDPR__ block
// above) and MUST be passed via the `measures` argument of sendTelemetryEvent, not
// as properties. Fields annotated `isMeasurement: true` are dropped by telemetry
// ingestion when sent in the properties bag.
};
/**
* Telemetry event sent when cancelling discovering tests
Expand Down Expand Up @@ -2286,14 +2282,10 @@ export interface IEventNamePropertyMapping {
* Coarse failure category when `failed` is true.
*/
failureCategory?: UnitTestRunFailureCategory;
/**
* Wall-clock duration of the run in milliseconds.
*/
durationMs?: number;
/**
* Number of test items the user asked to run.
*/
requestedCount?: number;
// NOTE: `durationMs` and `requestedCount` are measurements (see the __GDPR__ block
// above) and MUST be passed via the `measures` argument of sendTelemetryEvent, not
// as properties. Fields annotated `isMeasurement: true` are dropped by telemetry
// ingestion when sent in the properties bag.
};
/**
* Telemetry event sent when testing is disabled for a workspace.
Expand Down
20 changes: 11 additions & 9 deletions src/client/testing/testController/common/projectTestExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,17 @@ export async function executeTestsForProjects(
traceError(`[test-by-project] Execution failed for project ${project.projectName}:`, error);
}
} finally {
sendTelemetryEvent(EventName.UNITTEST_RUN_DONE, undefined, {
tool: project.testProvider,
debugging: isDebugMode,
mode: 'project',
failed,
failureCategory,
durationMs: stopWatch.elapsedTime,
requestedCount: items.length,
});
sendTelemetryEvent(
EventName.UNITTEST_RUN_DONE,
{ durationMs: stopWatch.elapsedTime, requestedCount: items.length },
{
tool: project.testProvider,
debugging: isDebugMode,
mode: 'project',
failed,
failureCategory,
},
);
}
});

Expand Down
12 changes: 9 additions & 3 deletions src/client/testing/testController/common/resultResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,20 @@ export class PythonResultResolver implements ITestResultResolver {
const cycle = this.discoveryTelemetry.complete();
const mode = cycle?.mode ?? this.discoveryTelemetry.defaultMode;
const failed = payload?.status === 'error';
sendTelemetryEvent(EventName.UNITTEST_DISCOVERY_DONE, undefined, {
// Numeric fields must be sent as measures (2nd arg), not properties. Fields
// annotated `isMeasurement: true` are dropped by telemetry ingestion when they
// arrive in the properties bag, so totalDurationMs/testCount would otherwise never
// be recorded.
const measures: Record<string, number> = { testCount };
if (cycle?.stopWatch.elapsedTime !== undefined) {
measures.totalDurationMs = cycle.stopWatch.elapsedTime;
}
sendTelemetryEvent(EventName.UNITTEST_DISCOVERY_DONE, measures, {
tool: this.testProvider,
failed,
mode,
trigger: cycle?.trigger,
failureCategory: failed ? (token?.isCancellationRequested ? 'cancelled' : 'unknown') : undefined,
totalDurationMs: cycle?.stopWatch.elapsedTime,
testCount,
});
}

Expand Down
27 changes: 16 additions & 11 deletions src/client/testing/testController/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,13 +716,16 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
// Individual project failures don't block others
projectsCompleted.add(project.projectUri.toString()); // Still mark as completed
const cycle = (project.resultResolver as Partial<PythonResultResolver>).discoveryTelemetry?.complete();
sendTelemetryEvent(EventName.UNITTEST_DISCOVERY_DONE, undefined, {
const measures: Record<string, number> = {};
if (cycle?.stopWatch.elapsedTime !== undefined) {
measures.totalDurationMs = cycle.stopWatch.elapsedTime;
}
sendTelemetryEvent(EventName.UNITTEST_DISCOVERY_DONE, measures, {
tool: project.testProvider,
failed: true,
mode: 'project',
trigger: cycle?.trigger ?? this.currentDiscoveryTrigger,
failureCategory: this.refreshCancellation.token.isCancellationRequested ? 'cancelled' : 'unknown',
totalDurationMs: cycle?.stopWatch.elapsedTime,
});
} finally {
project.isDiscovering = false;
Expand Down Expand Up @@ -1048,15 +1051,17 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
failureCategory = token.isCancellationRequested ? 'cancelled' : 'unknown';
throw ex;
} finally {
sendTelemetryEvent(EventName.UNITTEST_RUN_DONE, undefined, {
tool: provider,
debugging,
mode: 'legacy',
failed,
failureCategory,
durationMs: stopWatch.elapsedTime,
requestedCount: testItems.length,
});
sendTelemetryEvent(
EventName.UNITTEST_RUN_DONE,
{ durationMs: stopWatch.elapsedTime, requestedCount: testItems.length },
{
tool: provider,
debugging,
mode: 'legacy',
failed,
failureCategory,
},
);
}
}

Expand Down
19 changes: 11 additions & 8 deletions src/client/testing/testController/workspaceTestAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,17 @@ export class WorkspaceTestAdapter {
deferred.resolve();
} catch (ex) {
const cycle = (this.resultResolver as Partial<PythonResultResolver>).discoveryTelemetry?.complete();
sendTelemetryEvent(EventName.UNITTEST_DISCOVERY_DONE, undefined, {
tool: this.testProvider,
failed: true,
mode: 'legacy',
trigger: cycle?.trigger ?? trigger,
failureCategory: token?.isCancellationRequested ? 'cancelled' : 'unknown',
totalDurationMs: cycle?.stopWatch.elapsedTime ?? stopWatch.elapsedTime,
});
sendTelemetryEvent(
EventName.UNITTEST_DISCOVERY_DONE,
{ totalDurationMs: cycle?.stopWatch.elapsedTime ?? stopWatch.elapsedTime },
{
tool: this.testProvider,
failed: true,
mode: 'legacy',
trigger: cycle?.trigger ?? trigger,
failureCategory: token?.isCancellationRequested ? 'cancelled' : 'unknown',
},
);

let cancel = token?.isCancellationRequested
? Testing.cancelUnittestDiscovery
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ suite('Result Resolver tests', () => {

resultResolver.resolveDiscovery(payload, cancelationToken);

sinon.assert.calledWithMatch(sendTelemetryStub, EventName.UNITTEST_DISCOVERY_DONE, undefined, {
sinon.assert.calledWithMatch(sendTelemetryStub, EventName.UNITTEST_DISCOVERY_DONE, sinon.match.any, {
failed: true,
failureCategory: 'unknown',
});
Expand Down
Loading