forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathdebugSessionTelemetry.ts
More file actions
80 lines (69 loc) · 3.07 KB
/
debugSessionTelemetry.ts
File metadata and controls
80 lines (69 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { inject, injectable } from 'inversify';
import { DebugAdapterTracker, DebugAdapterTrackerFactory, DebugSession, ProviderResult } from 'vscode';
import { DebugProtocol } from 'vscode-debugprotocol';
import { IExtensionSingleActivationService } from '../../activation/types';
import { AttachRequestArguments, ConsoleType, LaunchRequestArguments, TriggerType } from '../../debugger/types';
import { sendTelemetryEvent } from '../../telemetry';
import { EventName } from '../../telemetry/constants';
import { IDisposableRegistry } from '../types';
import { StopWatch } from '../utils/stopWatch';
import { IDebugService } from './types';
function isResponse(a: any): a is DebugProtocol.Response {
return a.type === 'response';
}
class TelemetryTracker implements DebugAdapterTracker {
private timer = new StopWatch();
private readonly trigger: TriggerType = 'launch';
private readonly console: ConsoleType | undefined;
constructor(session: DebugSession) {
this.trigger = session.configuration.request as TriggerType;
const debugConfiguration = session.configuration as Partial<LaunchRequestArguments & AttachRequestArguments>;
this.console = debugConfiguration.console;
}
public onWillStartSession() {
this.sendTelemetry(EventName.DEBUG_SESSION_START);
}
public onDidSendMessage(message: any): void {
if (isResponse(message)) {
if (message.command === 'configurationDone') {
// "configurationDone" response is sent immediately after user code starts running.
this.sendTelemetry(EventName.DEBUG_SESSION_USER_CODE_RUNNING);
}
}
}
public onWillStopSession(): void {
this.sendTelemetry(EventName.DEBUG_SESSION_STOP);
}
public onError?(_error: Error): void {
this.sendTelemetry(EventName.DEBUG_SESSION_ERROR);
}
private sendTelemetry(eventName: EventName): void {
if (eventName === EventName.DEBUG_SESSION_START) {
this.timer.reset();
}
const telemetryProps = {
trigger: this.trigger,
console: this.console,
};
sendTelemetryEvent(eventName, this.timer.elapsedTime, telemetryProps);
}
}
@injectable()
export class DebugSessionTelemetry implements DebugAdapterTrackerFactory, IExtensionSingleActivationService {
public readonly supportedWorkspaceTypes = { untrustedWorkspace: false, virtualWorkspace: true };
constructor(
@inject(IDisposableRegistry) disposableRegistry: IDisposableRegistry,
@inject(IDebugService) debugService: IDebugService,
) {
disposableRegistry.push(debugService.registerDebugAdapterTrackerFactory('python', this));
}
public async activate(): Promise<void> {
// We actually register in the constructor. Not necessary to do it here
}
public createDebugAdapterTracker(session: DebugSession): ProviderResult<DebugAdapterTracker> {
return new TelemetryTracker(session);
}
}