Skip to content

Commit 47a5cd8

Browse files
Add missing telemetry and extra logging (#391)
* Add missing telemetry and extra logging * fix lint * Add more log and telemetry * Add more logging * fix lint * add telemery for inline
1 parent 695d259 commit 47a5cd8

File tree

13 files changed

+68
-4
lines changed

13 files changed

+68
-4
lines changed

src/extension/common/application/debugSessionTelemetry.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,21 @@ class TelemetryTracker implements DebugAdapterTracker {
4141
this.sendTelemetry(EventName.DEBUG_SESSION_STOP);
4242
}
4343

44-
public onError?(_error: Error): void {
45-
this.sendTelemetry(EventName.DEBUG_SESSION_ERROR);
44+
public onError?(error: Error): void {
45+
this.sendTelemetry(EventName.DEBUG_SESSION_ERROR, error);
4646
}
4747

48-
private sendTelemetry(eventName: EventName): void {
48+
private sendTelemetry<P extends IEventNamePropertyMapping, E extends keyof P>(
49+
eventName: EventName,
50+
properties?: P[E],
51+
): void {
4952
if (eventName === EventName.DEBUG_SESSION_START) {
5053
this.timer.reset();
5154
}
5255
const telemetryProps = {
5356
trigger: this.trigger,
5457
console: this.console,
58+
...properties,
5559
};
5660
sendTelemetryEvent(eventName as keyof IEventNamePropertyMapping, this.timer.elapsedTime, telemetryProps);
5761
}

src/extension/debugger/adapter/factory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac
149149
}
150150

151151
private async showDeprecatedPythonMessage() {
152+
sendTelemetryEvent(EventName.DEBUGGER_PYTHON_37_DEPRECATED);
152153
const notificationPromptEnabled = this.persistentState.createGlobalPersistentState(
153154
debugStateKeys.doNotShowAgain,
154155
false,

src/extension/debugger/configuration/dynamicdebugConfigurationService.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { IDynamicDebugConfigurationService } from '../types';
1010
import { DebuggerTypeName } from '../../constants';
1111
import { replaceAll } from '../../common/stringUtils';
1212
import { getDjangoPaths, getFastApiPaths, getFlaskPaths } from './utils/configuration';
13+
import { sendTelemetryEvent } from '../../telemetry';
14+
import { EventName } from '../../telemetry/constants';
1315

1416
const workspaceFolderToken = '${workspaceFolder}';
1517

@@ -74,6 +76,8 @@ export class DynamicPythonDebugConfigurationService implements IDynamicDebugConf
7476
});
7577
}
7678

79+
sendTelemetryEvent(EventName.DEBUGGER_DYNAMIC_CONFIGURATION, undefined, { providers: providers });
80+
7781
return providers;
7882
}
7983
}

src/extension/debugger/configuration/launch.json/launchJsonReader.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ import * as fs from 'fs-extra';
66
import { parse } from 'jsonc-parser';
77
import { DebugConfiguration, Uri, WorkspaceFolder } from 'vscode';
88
import { getConfiguration, getWorkspaceFolder } from '../../../common/vscodeapi';
9+
import { traceLog } from '../../../common/log/logging';
910

1011
export async function getConfigurationsForWorkspace(workspace: WorkspaceFolder): Promise<DebugConfiguration[]> {
12+
traceLog('Getting configurations for workspace');
1113
const filename = path.join(workspace.uri.fsPath, '.vscode', 'launch.json');
1214
if (!(await fs.pathExists(filename))) {
1315
// Check launch config in the workspace file
1416
const codeWorkspaceConfig = getConfiguration('launch', workspace);
1517
if (!codeWorkspaceConfig.configurations || !Array.isArray(codeWorkspaceConfig.configurations)) {
1618
return [];
1719
}
20+
traceLog('Using configuration in workspace');
1821
return codeWorkspaceConfig.configurations;
1922
}
2023

@@ -26,7 +29,7 @@ export async function getConfigurationsForWorkspace(workspace: WorkspaceFolder):
2629
if (!parsed.version) {
2730
throw Error('Missing field in launch.json: version');
2831
}
29-
// We do not bother ensuring each item is a DebugConfiguration...
32+
traceLog('Using configuration in launch.json');
3033
return parsed.configurations;
3134
}
3235

src/extension/debugger/configuration/resolvers/attach.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import { getOSType, OSType } from '../../../common/platform';
88
import { AttachRequestArguments, DebugOptions, PathMapping } from '../../../types';
99
import { BaseConfigurationResolver } from './base';
1010
import { getConfiguration } from '../../../common/vscodeapi';
11+
import { traceLog } from '../../../common/log/logging';
1112

1213
export class AttachConfigurationResolver extends BaseConfigurationResolver<AttachRequestArguments> {
1314
public async resolveDebugConfigurationWithSubstitutedVariables(
1415
folder: WorkspaceFolder | undefined,
1516
debugConfiguration: AttachRequestArguments,
1617
_token?: CancellationToken,
1718
): Promise<AttachRequestArguments | undefined> {
19+
traceLog('Resolving attach configuration with substituted variables');
1820
const workspaceFolder = AttachConfigurationResolver.getWorkspaceFolder(folder);
1921

2022
await this.provideAttachDefaults(workspaceFolder, debugConfiguration as AttachRequestArguments);

src/extension/debugger/configuration/resolvers/base.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { resolveVariables } from '../utils/common';
1616
import { getProgram } from './helper';
1717
import { getSettingsPythonPath, getInterpreterDetails } from '../../../common/python';
1818
import { getOSType, OSType } from '../../../common/platform';
19+
import { traceLog } from '../../../common/log/logging';
1920

2021
export abstract class BaseConfigurationResolver<T extends DebugConfiguration>
2122
implements IDebugConfigurationResolver<T>
@@ -62,14 +63,17 @@ export abstract class BaseConfigurationResolver<T extends DebugConfiguration>
6263
const workspaceFolders = getWorkspaceFolders();
6364

6465
if (!Array.isArray(workspaceFolders) || workspaceFolders.length === 0) {
66+
traceLog('No workspace folder found');
6567
return program ? Uri.file(path.dirname(program)) : undefined;
6668
}
6769
if (workspaceFolders.length === 1) {
70+
traceLog('Using the only workspaceFolder found: ', workspaceFolders[0].uri.fsPath);
6871
return workspaceFolders[0].uri;
6972
}
7073
if (program) {
7174
const workspaceFolder = getVSCodeWorkspaceFolder(Uri.file(program));
7275
if (workspaceFolder) {
76+
traceLog('Using workspaceFolder found for the program: ', workspaceFolder.uri.fsPath);
7377
return workspaceFolder.uri;
7478
}
7579
}

src/extension/debugger/configuration/resolvers/launch.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { resolveVariables } from '../utils/common';
1212
import { BaseConfigurationResolver } from './base';
1313
import { getDebugEnvironmentVariables, getProgram } from './helper';
1414
import { getConfiguration } from '../../../common/vscodeapi';
15+
import { traceLog } from '../../../common/log/logging';
1516

1617
export class LaunchConfigurationResolver extends BaseConfigurationResolver<LaunchRequestArguments> {
1718
public async resolveDebugConfiguration(
@@ -51,6 +52,7 @@ export class LaunchConfigurationResolver extends BaseConfigurationResolver<Launc
5152
debugConfiguration: LaunchRequestArguments,
5253
_token?: CancellationToken,
5354
): Promise<LaunchRequestArguments | undefined> {
55+
traceLog('Resolving launch configuration with substituted variables');
5456
const workspaceFolder = LaunchConfigurationResolver.getWorkspaceFolder(folder);
5557
await this.provideLaunchDefaults(workspaceFolder, debugConfiguration);
5658

src/extension/debugger/hooks/childProcessAttachService.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { AttachRequestArguments } from '../../types';
1010
import { IChildProcessAttachService } from './types';
1111
import { getWorkspaceFolders, showErrorMessage } from '../../common/vscodeapi';
1212
import { noop } from '../../common/utils/misc';
13+
import { traceLog } from '../../common/log/logging';
1314

1415
/**
1516
* This class is responsible for attaching the debugger to any
@@ -27,6 +28,7 @@ export class ChildProcessAttachService implements IChildProcessAttachService {
2728
lifecycleManagedByParent: true,
2829
};
2930
const folder = this.getRelatedWorkspaceFolder(debugConfig);
31+
traceLog('Start debugger in the attach child proccess');
3032
const launched = await debug.startDebugging(folder, debugConfig, debugSessionOption);
3133
if (!launched) {
3234
showErrorMessage(l10n.t('Failed to launch debugger for child process {0}', debugConfig.subProcessId!)).then(

src/extension/debugger/hooks/debugpySocketsHandler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { DebuggerEvents } from './constants';
1010
import { DebuggerTypeName } from '../../constants';
1111
import { DebugPortAttributesProvider } from '../debugPort/portAttributesProvider';
1212
import { IDebugSessionEventHandlers } from './types';
13+
import { traceLog } from '../../common/log/logging';
1314

1415
/**
1516
* This class is responsible for register ports using by debugpy in the portProvider.
@@ -30,6 +31,7 @@ export class DebugpySocketsHandler implements IDebugSessionEventHandlers {
3031
}
3132

3233
if (event.event === DebuggerEvents.DebugpySockets) {
34+
traceLog("Received 'debugpySockets' event from debugpy.");
3335
let portSocket = event.body.sockets.find((socket: { [x: string]: any }) => {
3436
return socket['internal'] === false;
3537
});

src/extension/debugger/inlineValue/pythonInlineValueProvider.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
InlineValueEvaluatableExpression,
1212
} from 'vscode';
1313
import { customRequest } from '../../common/vscodeapi';
14+
import { sendTelemetryEvent } from '../../telemetry';
15+
import { EventName } from '../../telemetry/constants';
1416

1517
export class PythonInlineValueProvider implements InlineValuesProvider {
1618
public async provideInlineValues(
@@ -100,6 +102,7 @@ export class PythonInlineValueProvider implements InlineValuesProvider {
100102
}
101103
}
102104
}
105+
sendTelemetryEvent(EventName.DEBUGGER_SHOW_PYTHON_INLINE_VALUES);
103106
return allValues;
104107
}
105108
}

src/extension/extensionInit.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import { buildApi } from './api';
5050
import { IExtensionApi } from './apiTypes';
5151
import { registerHexDebugVisualizationTreeProvider } from './debugger/visualizers/inlineHexDecoder';
5252
import { PythonInlineValueProvider } from './debugger/inlineValue/pythonInlineValueProvider';
53+
import { traceLog } from './common/log/logging';
5354

5455
export async function registerDebugger(context: IExtensionContext): Promise<IExtensionApi> {
5556
const childProcessAttachService = new ChildProcessAttachService();
@@ -83,6 +84,7 @@ export async function registerDebugger(context: IExtensionContext): Promise<IExt
8384

8485
context.subscriptions.push(
8586
registerCommand(Commands.Debug_In_Terminal, async (file?: Uri) => {
87+
traceLog("Debugging using the editor button 'Debug in terminal'");
8688
sendTelemetryEvent(EventName.DEBUG_IN_TERMINAL_BUTTON);
8789
const interpreter = await getInterpreterDetails(file);
8890
if (!interpreter.path) {
@@ -96,6 +98,7 @@ export async function registerDebugger(context: IExtensionContext): Promise<IExt
9698

9799
context.subscriptions.push(
98100
registerCommand(Commands.Debug_Using_Launch_Config, async (file?: Uri) => {
101+
traceLog("Debugging using the editor button 'Debug using the launch.json'");
99102
sendTelemetryEvent(EventName.DEBUG_USING_LAUNCH_CONFIG_BUTTON);
100103
const interpreter = await getInterpreterDetails(file);
101104

src/extension/telemetry/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ export enum EventName {
1313
DEBUG_SESSION_START = 'DEBUG_SESSION.START',
1414
DEBUG_SESSION_STOP = 'DEBUG_SESSION.STOP',
1515
DEBUG_SESSION_USER_CODE_RUNNING = 'DEBUG_SESSION.USER_CODE_RUNNING',
16+
DEBUG_SHOW_INLINE_HEX_VALUE = 'DEBUG.SHOW_INLINE_HEX_VALUE',
1617
DEBUGGER = 'DEBUGGER',
1718
DEBUGGER_ATTACH_TO_CHILD_PROCESS = 'DEBUGGER.ATTACH_TO_CHILD_PROCESS',
1819
DEBUGGER_ATTACH_TO_LOCAL_PROCESS = 'DEBUGGER.ATTACH_TO_LOCAL_PROCESS',
1920
DEBUGGER_CONFIGURATION_PROMPTS = 'DEBUGGER.CONFIGURATION.PROMPTS',
2021
DEBUGGER_CONFIGURATION_PROMPTS_IN_LAUNCH_JSON = 'DEBUGGER.CONFIGURATION.PROMPTS.IN.LAUNCH.JSON',
22+
DEBUGGER_DYNAMIC_CONFIGURATION = 'DEBUGGER.DYNAMIC_CONFIGURATION',
2123
ENVFILE_VARIABLE_SUBSTITUTION = 'ENVFILE_VARIABLE_SUBSTITUTION',
2224
USE_REPORT_ISSUE_COMMAND = 'USE_REPORT_ISSUE_COMMAND',
25+
DEBUGGER_PYTHON_37_DEPRECATED = 'DEBUGGER_PYTHON_37_DEPRECATED',
26+
DEBUGGER_SHOW_PYTHON_INLINE_VALUES = 'DEBUGGER_SHOW_PYTHON_INLINE_VALUES',
2327
}

src/extension/telemetry/index.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { DebugConfigurationType } from '../debugger/types';
1111
import { EventName } from './constants';
1212
import { isPromise } from '../common/utils/async';
1313
import { getTelemetryReporter } from './reporter';
14+
import { DebugConfiguration } from 'vscode';
1415

1516
/**
1617
* Checks whether telemetry is supported.
@@ -346,6 +347,7 @@ export interface IEventNamePropertyMapping {
346347
* @type {ConsoleType}
347348
*/
348349
console?: ConsoleType;
350+
error?: Error;
349351
};
350352
/**
351353
* Telemetry captured after stopping debug session.
@@ -660,4 +662,32 @@ export interface IEventNamePropertyMapping {
660662
"use_report_issue_command" : { "owner": "paulacamargo25" }
661663
*/
662664
[EventName.USE_REPORT_ISSUE_COMMAND]: unknown;
665+
/**
666+
* Telemetry event sent when providing dynamic configuration for debugger
667+
*/
668+
/* __GDPR__
669+
"debugger_dynamic_config" : { "owner": "paulacamargo25" }
670+
*/
671+
[EventName.DEBUGGER_DYNAMIC_CONFIGURATION]: {
672+
/**
673+
* Providers of dynamic configurations
674+
*
675+
* @type {DebugConfiguration[]}
676+
*/
677+
providers: DebugConfiguration[];
678+
};
679+
/**
680+
* Telemetry event sent when the debugger is running with a non supports python versions minor than 3.7.
681+
*/
682+
/* __GDPR__
683+
"DEBUGGER_PYTHON_37_DEPRECATED" : { "owner": "paulacamargo25" }
684+
*/
685+
[EventName.DEBUGGER_PYTHON_37_DEPRECATED]: never | undefined;
686+
/**
687+
* Telemetry event sent when displaying inline values in the debugger.
688+
*/
689+
/* __GDPR__
690+
"DEBUGGER_SHOW_PYTHON_INLINE_VALUES" : { "owner": "paulacamargo25" }
691+
*/
692+
[EventName.DEBUGGER_SHOW_PYTHON_INLINE_VALUES]: never | undefined;
663693
}

0 commit comments

Comments
 (0)