Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
Introduces a telemetry collector, so a request handling logic can app…
Browse files Browse the repository at this point in the history
…end additional properties reported in the request telemetry.

# Conflicts:
#	src/chrome/chromeDebugAdapter.ts
#	src/chrome/chromeDebugSession.ts
  • Loading branch information
changsi-an committed Mar 23, 2018
1 parent e488c9f commit bfc8fb4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/chrome/chromeDebugAdapter.ts
Expand Up @@ -9,7 +9,7 @@ import { ICommonRequestArgs, ILaunchRequestArgs, ISetBreakpointsArgs, ISetBreakp
IAttachRequestArgs, IScopesResponseBody, IVariablesResponseBody,
ISourceResponseBody, IThreadsResponseBody, IEvaluateResponseBody, ISetVariableResponseBody, IDebugAdapter,
ICompletionsResponseBody, IToggleSkipFileStatusArgs, IInternalStackTraceResponseBody, IGetLoadedSourcesResponseBody,
IExceptionInfoResponseBody, ISetBreakpointResult, TimeTravelRuntime, IRestartRequestArgs, IInitializeRequestArgs } from '../debugAdapterInterfaces';
IExceptionInfoResponseBody, ISetBreakpointResult, TimeTravelRuntime, IRestartRequestArgs, IInitializeRequestArgs, ITelemetryPropertyCollector } from '../debugAdapterInterfaces';
import { IChromeDebugAdapterOpts, ChromeDebugSession } from './chromeDebugSession';
import { ChromeConnection } from './chromeConnection';
import * as ChromeUtils from './chromeUtils';
Expand Down Expand Up @@ -284,7 +284,7 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
return !!this._breakOnLoadHelper;
}

public async launch(args: ILaunchRequestArgs): Promise<void> {
public async launch(args: ILaunchRequestArgs, telemetryPropertyCollector: ITelemetryPropertyCollector): Promise<void> {
this.commonArgs(args);
this._sourceMapTransformer.launch(args);
this._pathTransformer.launch(args);
Expand Down
12 changes: 8 additions & 4 deletions src/chrome/chromeDebugSession.ts
Expand Up @@ -13,7 +13,7 @@ import { BaseSourceMapTransformer } from '../transformers/baseSourceMapTransform
import { LineColTransformer } from '../transformers/lineNumberTransformer';

import { IDebugAdapter } from '../debugAdapterInterfaces';
import { telemetry, ExceptionType, IExecutionResultTelemetryProperties } from '../telemetry';
import { telemetry, ExceptionType, IExecutionResultTelemetryProperties, TelemetryPropertyCollector } from '../telemetry';
import * as utils from '../utils';
import { ExecutionTimingsReporter, StepProgressEventsEmitter, IObservableEvents, IStepStartedEventsEmitter, IFinishedStartingUpEventsEmitter } from '../executionTimingsReporter';

Expand Down Expand Up @@ -124,8 +124,9 @@ export class ChromeDebugSession extends LoggingDebugSession implements IObservab
* Overload dispatchRequest to the debug adapters' Promise-based methods instead of DebugSession's callback-based methods
*/
protected dispatchRequest(request: DebugProtocol.Request): void {
const telemetryPropertyCollector = new TelemetryPropertyCollector();
// We want the request to be non-blocking, so we won't await for reportTelemetry
this.reportTelemetry(`ClientRequest/${request.command}`, { requestType: request.type }, async (reportFailure) => {
this.reportTelemetry(`ClientRequest/${request.command}`, { requestType: request.type }, telemetryPropertyCollector, async (reportFailure) => {
const response: DebugProtocol.Response = new Response(request);
try {
logger.verbose(`From client: ${request.command}(${JSON.stringify(request.arguments) })`);
Expand All @@ -134,7 +135,7 @@ export class ChromeDebugSession extends LoggingDebugSession implements IObservab
reportFailure('The debug adapter doesn\'t recognize this command');
this.sendUnknownCommandResponse(response, request.command);
} else {
response.body = await this._debugAdapter[request.command](request.arguments, request.seq);
response.body = await this._debugAdapter[request.command](request.arguments, telemetryPropertyCollector, request.seq);
this.sendResponse(response);
}
} catch (e) {
Expand All @@ -147,7 +148,9 @@ export class ChromeDebugSession extends LoggingDebugSession implements IObservab
}

// { command: request.command, type: request.type };
private async reportTelemetry(eventName: string, propertiesSpecificToAction: {[property: string]: string}, action: (reportFailure: (failure: any) => void) => Promise<void>): Promise<void> {
private async reportTelemetry(eventName: string, propertiesSpecificToAction: {[property: string]: string},
telemetryPropertyCollector: TelemetryPropertyCollector,
action: (reportFailure: (failure: any) => void) => Promise<void>): Promise<void> {
const startProcessingTime = process.hrtime();
const startTime = Date.now();
const isSequentialRequest = eventName === 'ClientRequest/initialize' || eventName === 'ClientRequest/launch' || eventName === 'ClientRequest/attach';
Expand All @@ -166,6 +169,7 @@ export class ChromeDebugSession extends LoggingDebugSession implements IObservab
} else {
this.events.emitRequestCompleted(eventName, startTime, timeTakenInMilliseconds);
}
Object.assign(properties, telemetryPropertyCollector.getProperties());
telemetry.reportEvent(eventName, properties);
};

Expand Down
4 changes: 3 additions & 1 deletion src/debugAdapterInterfaces.d.ts
Expand Up @@ -8,11 +8,13 @@

import { DebugProtocol } from 'vscode-debugprotocol';
import Crdp from '../crdp/crdp';
import { ITelemetryPropertyCollector } from './telemetry';

export type ISourceMapPathOverrides = { [pattern: string]: string };

export type BreakOnLoadStrategy = 'regex' | 'instrument' | 'off';

export { ITelemetryPropertyCollector } from './telemetry';
/**
* Properties valid for both Launch and Attach
*/
Expand Down Expand Up @@ -179,7 +181,7 @@ export interface IDebugAdapter {
shutdown(): void;

initialize(args: DebugProtocol.InitializeRequestArguments, requestSeq?: number): PromiseOrNot<DebugProtocol.Capabilities>;
launch(args: ILaunchRequestArgs, requestSeq?: number): PromiseOrNot<void>;
launch(args: ILaunchRequestArgs, telemetryPropertyCollector: ITelemetryPropertyCollector, requestSeq?: number): PromiseOrNot<void>;
attach(args: IAttachRequestArgs, requestSeq?: number): PromiseOrNot<void>;
disconnect(args: DebugProtocol.DisconnectArguments): PromiseOrNot<void>;
setBreakpoints(args: DebugProtocol.SetBreakpointsArguments, requestSeq?: number): PromiseOrNot<ISetBreakpointsResponseBody>;
Expand Down
17 changes: 17 additions & 0 deletions src/telemetry.ts
Expand Up @@ -209,4 +209,21 @@ export class BatchTelemetryReporter {
}
}

export interface ITelemetryPropertyCollector {
getProperties(): {[propertyName: string]: string};
addTelemetryProperty(propertyName: string, value: string): void;
}

export class TelemetryPropertyCollector implements ITelemetryPropertyCollector {
private _properties: {[propertyName: string]: string} = {};

public getProperties() {
return this._properties;
}

public addTelemetryProperty(propertyName: string, value: string) {
this._properties[propertyName] = value;
}
}

export const telemetry = new AsyncGlobalPropertiesTelemetryReporter(new TelemetryReporter());

0 comments on commit bfc8fb4

Please sign in to comment.