Skip to content

Add missing telemetry and extra logging #391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
10 changes: 7 additions & 3 deletions src/extension/common/application/debugSessionTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,21 @@ class TelemetryTracker implements DebugAdapterTracker {
this.sendTelemetry(EventName.DEBUG_SESSION_STOP);
}

public onError?(_error: Error): void {
this.sendTelemetry(EventName.DEBUG_SESSION_ERROR);
public onError?(error: Error): void {
this.sendTelemetry(EventName.DEBUG_SESSION_ERROR, error);
}

private sendTelemetry(eventName: EventName): void {
private sendTelemetry<P extends IEventNamePropertyMapping, E extends keyof P>(
eventName: EventName,
properties?: P[E],
): void {
if (eventName === EventName.DEBUG_SESSION_START) {
this.timer.reset();
}
const telemetryProps = {
trigger: this.trigger,
console: this.console,
...properties,
};
sendTelemetryEvent(eventName as keyof IEventNamePropertyMapping, this.timer.elapsedTime, telemetryProps);
}
Expand Down
1 change: 1 addition & 0 deletions src/extension/debugger/adapter/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac
}

private async showDeprecatedPythonMessage() {
sendTelemetryEvent(EventName.DEBUGGER_PYTHON_37_DEPRECATED);
const notificationPromptEnabled = this.persistentState.createGlobalPersistentState(
debugStateKeys.doNotShowAgain,
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { IDynamicDebugConfigurationService } from '../types';
import { DebuggerTypeName } from '../../constants';
import { replaceAll } from '../../common/stringUtils';
import { getDjangoPaths, getFastApiPaths, getFlaskPaths } from './utils/configuration';
import { sendTelemetryEvent } from '../../telemetry';
import { EventName } from '../../telemetry/constants';

const workspaceFolderToken = '${workspaceFolder}';

Expand Down Expand Up @@ -74,6 +76,8 @@ export class DynamicPythonDebugConfigurationService implements IDynamicDebugConf
});
}

sendTelemetryEvent(EventName.DEBUGGER_DYNAMIC_CONFIGURATION, undefined, { providers: providers });

return providers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ import * as fs from 'fs-extra';
import { parse } from 'jsonc-parser';
import { DebugConfiguration, Uri, WorkspaceFolder } from 'vscode';
import { getConfiguration, getWorkspaceFolder } from '../../../common/vscodeapi';
import { traceLog } from '../../../common/log/logging';

export async function getConfigurationsForWorkspace(workspace: WorkspaceFolder): Promise<DebugConfiguration[]> {
traceLog('Getting configurations for workspace');
const filename = path.join(workspace.uri.fsPath, '.vscode', 'launch.json');
if (!(await fs.pathExists(filename))) {
// Check launch config in the workspace file
const codeWorkspaceConfig = getConfiguration('launch', workspace);
if (!codeWorkspaceConfig.configurations || !Array.isArray(codeWorkspaceConfig.configurations)) {
return [];
}
traceLog('Using configuration in workspace');
return codeWorkspaceConfig.configurations;
}

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

Expand Down
2 changes: 2 additions & 0 deletions src/extension/debugger/configuration/resolvers/attach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import { getOSType, OSType } from '../../../common/platform';
import { AttachRequestArguments, DebugOptions, PathMapping } from '../../../types';
import { BaseConfigurationResolver } from './base';
import { getConfiguration } from '../../../common/vscodeapi';
import { traceLog } from '../../../common/log/logging';

export class AttachConfigurationResolver extends BaseConfigurationResolver<AttachRequestArguments> {
public async resolveDebugConfigurationWithSubstitutedVariables(
folder: WorkspaceFolder | undefined,
debugConfiguration: AttachRequestArguments,
_token?: CancellationToken,
): Promise<AttachRequestArguments | undefined> {
traceLog('Resolving attach configuration with substituted variables');
const workspaceFolder = AttachConfigurationResolver.getWorkspaceFolder(folder);

await this.provideAttachDefaults(workspaceFolder, debugConfiguration as AttachRequestArguments);
Expand Down
4 changes: 4 additions & 0 deletions src/extension/debugger/configuration/resolvers/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { resolveVariables } from '../utils/common';
import { getProgram } from './helper';
import { getSettingsPythonPath, getInterpreterDetails } from '../../../common/python';
import { getOSType, OSType } from '../../../common/platform';
import { traceLog } from '../../../common/log/logging';

export abstract class BaseConfigurationResolver<T extends DebugConfiguration>
implements IDebugConfigurationResolver<T>
Expand Down Expand Up @@ -62,14 +63,17 @@ export abstract class BaseConfigurationResolver<T extends DebugConfiguration>
const workspaceFolders = getWorkspaceFolders();

if (!Array.isArray(workspaceFolders) || workspaceFolders.length === 0) {
traceLog('No workspace folder found');
return program ? Uri.file(path.dirname(program)) : undefined;
}
if (workspaceFolders.length === 1) {
traceLog('Using the only workspaceFolder found: ', workspaceFolders[0].uri.fsPath);
return workspaceFolders[0].uri;
}
if (program) {
const workspaceFolder = getVSCodeWorkspaceFolder(Uri.file(program));
if (workspaceFolder) {
traceLog('Using workspaceFolder found for the program: ', workspaceFolder.uri.fsPath);
return workspaceFolder.uri;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/extension/debugger/configuration/resolvers/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { resolveVariables } from '../utils/common';
import { BaseConfigurationResolver } from './base';
import { getDebugEnvironmentVariables, getProgram } from './helper';
import { getConfiguration } from '../../../common/vscodeapi';
import { traceLog } from '../../../common/log/logging';

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

Expand Down
2 changes: 2 additions & 0 deletions src/extension/debugger/hooks/childProcessAttachService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { AttachRequestArguments } from '../../types';
import { IChildProcessAttachService } from './types';
import { getWorkspaceFolders, showErrorMessage } from '../../common/vscodeapi';
import { noop } from '../../common/utils/misc';
import { traceLog } from '../../common/log/logging';

/**
* This class is responsible for attaching the debugger to any
Expand All @@ -27,6 +28,7 @@ export class ChildProcessAttachService implements IChildProcessAttachService {
lifecycleManagedByParent: true,
};
const folder = this.getRelatedWorkspaceFolder(debugConfig);
traceLog('Start debugger in the attach child proccess');
const launched = await debug.startDebugging(folder, debugConfig, debugSessionOption);
if (!launched) {
showErrorMessage(l10n.t('Failed to launch debugger for child process {0}', debugConfig.subProcessId!)).then(
Expand Down
2 changes: 2 additions & 0 deletions src/extension/debugger/hooks/debugpySocketsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { DebuggerEvents } from './constants';
import { DebuggerTypeName } from '../../constants';
import { DebugPortAttributesProvider } from '../debugPort/portAttributesProvider';
import { IDebugSessionEventHandlers } from './types';
import { traceLog } from '../../common/log/logging';

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

if (event.event === DebuggerEvents.DebugpySockets) {
traceLog("Received 'debugpySockets' event from debugpy.");
let portSocket = event.body.sockets.find((socket: { [x: string]: any }) => {
return socket['internal'] === false;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
InlineValueEvaluatableExpression,
} from 'vscode';
import { customRequest } from '../../common/vscodeapi';
import { sendTelemetryEvent } from '../../telemetry';
import { EventName } from '../../telemetry/constants';

export class PythonInlineValueProvider implements InlineValuesProvider {
public async provideInlineValues(
Expand Down Expand Up @@ -100,6 +102,7 @@ export class PythonInlineValueProvider implements InlineValuesProvider {
}
}
}
sendTelemetryEvent(EventName.DEBUGGER_SHOW_PYTHON_INLINE_VALUES);
return allValues;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/extension/extensionInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { buildApi } from './api';
import { IExtensionApi } from './apiTypes';
import { registerHexDebugVisualizationTreeProvider } from './debugger/visualizers/inlineHexDecoder';
import { PythonInlineValueProvider } from './debugger/inlineValue/pythonInlineValueProvider';
import { traceLog } from './common/log/logging';

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

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

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

Expand Down
4 changes: 4 additions & 0 deletions src/extension/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ export enum EventName {
DEBUG_SESSION_START = 'DEBUG_SESSION.START',
DEBUG_SESSION_STOP = 'DEBUG_SESSION.STOP',
DEBUG_SESSION_USER_CODE_RUNNING = 'DEBUG_SESSION.USER_CODE_RUNNING',
DEBUG_SHOW_INLINE_HEX_VALUE = 'DEBUG.SHOW_INLINE_HEX_VALUE',
DEBUGGER = 'DEBUGGER',
DEBUGGER_ATTACH_TO_CHILD_PROCESS = 'DEBUGGER.ATTACH_TO_CHILD_PROCESS',
DEBUGGER_ATTACH_TO_LOCAL_PROCESS = 'DEBUGGER.ATTACH_TO_LOCAL_PROCESS',
DEBUGGER_CONFIGURATION_PROMPTS = 'DEBUGGER.CONFIGURATION.PROMPTS',
DEBUGGER_CONFIGURATION_PROMPTS_IN_LAUNCH_JSON = 'DEBUGGER.CONFIGURATION.PROMPTS.IN.LAUNCH.JSON',
DEBUGGER_DYNAMIC_CONFIGURATION = 'DEBUGGER.DYNAMIC_CONFIGURATION',
ENVFILE_VARIABLE_SUBSTITUTION = 'ENVFILE_VARIABLE_SUBSTITUTION',
USE_REPORT_ISSUE_COMMAND = 'USE_REPORT_ISSUE_COMMAND',
DEBUGGER_PYTHON_37_DEPRECATED = 'DEBUGGER_PYTHON_37_DEPRECATED',
DEBUGGER_SHOW_PYTHON_INLINE_VALUES = 'DEBUGGER_SHOW_PYTHON_INLINE_VALUES',
}
30 changes: 30 additions & 0 deletions src/extension/telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { DebugConfigurationType } from '../debugger/types';
import { EventName } from './constants';
import { isPromise } from '../common/utils/async';
import { getTelemetryReporter } from './reporter';
import { DebugConfiguration } from 'vscode';

/**
* Checks whether telemetry is supported.
Expand Down Expand Up @@ -346,6 +347,7 @@ export interface IEventNamePropertyMapping {
* @type {ConsoleType}
*/
console?: ConsoleType;
error?: Error;
};
/**
* Telemetry captured after stopping debug session.
Expand Down Expand Up @@ -660,4 +662,32 @@ export interface IEventNamePropertyMapping {
"use_report_issue_command" : { "owner": "paulacamargo25" }
*/
[EventName.USE_REPORT_ISSUE_COMMAND]: unknown;
/**
* Telemetry event sent when providing dynamic configuration for debugger
*/
/* __GDPR__
"debugger_dynamic_config" : { "owner": "paulacamargo25" }
*/
[EventName.DEBUGGER_DYNAMIC_CONFIGURATION]: {
/**
* Providers of dynamic configurations
*
* @type {DebugConfiguration[]}
*/
providers: DebugConfiguration[];
};
/**
* Telemetry event sent when the debugger is running with a non supports python versions minor than 3.7.
*/
/* __GDPR__
"DEBUGGER_PYTHON_37_DEPRECATED" : { "owner": "paulacamargo25" }
*/
[EventName.DEBUGGER_PYTHON_37_DEPRECATED]: never | undefined;
/**
* Telemetry event sent when displaying inline values in the debugger.
*/
/* __GDPR__
"DEBUGGER_SHOW_PYTHON_INLINE_VALUES" : { "owner": "paulacamargo25" }
*/
[EventName.DEBUGGER_SHOW_PYTHON_INLINE_VALUES]: never | undefined;
}
Loading