Skip to content

Commit 395ee88

Browse files
authored
Only trace TypeScript server call if we will log the request telemetry (#237)
1 parent 87eb44e commit 395ee88

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/extension/typescriptContext/vscode-node/languageContextService.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ class TelemetrySender {
265265
this.logService.logger.debug(`TypeScript Copilot context speculative request: [${context.requestId} - ${originalRequestId}, numberOfItems: ${numberOfItems}]`);
266266
}
267267

268+
public willLogRequestTelemetry(context: RequestContext): boolean {
269+
const sampleTelemetry = RequestContext.getSampleTelemetry(context);
270+
return sampleTelemetry === 1 || this.sendRequestTelemetryCounter % sampleTelemetry === 0;
271+
}
272+
268273
public sendRequestTelemetry(document: vscode.TextDocument, position: vscode.Position, context: RequestContext, data: ContextItemSummary, timeTaken: number, cacheState: { before: CacheState; after: CacheState } | undefined): void {
269274
const stats = data.stats;
270275
const nodePath = data?.path ? JSON.stringify(data.path) : JSON.stringify([0]);
@@ -1230,7 +1235,7 @@ type ComputeContextRequestArgs = {
12301235
$traceId?: string;
12311236
};
12321237
namespace ComputeContextRequestArgs {
1233-
export function create(document: vscode.TextDocument, position: vscode.Position, context: RequestContext, startTime: number, timeBudget: number, neighborFiles: readonly string[] | undefined, clientSideRunnableResults: readonly protocol.CachedContextRunnableResult[] | undefined): ComputeContextRequestArgs {
1238+
export function create(document: vscode.TextDocument, position: vscode.Position, context: RequestContext, startTime: number, timeBudget: number, willLogRequestTelemetry: boolean, neighborFiles: readonly string[] | undefined, clientSideRunnableResults: readonly protocol.CachedContextRunnableResult[] | undefined): ComputeContextRequestArgs {
12341239
return {
12351240
file: vscode.Uri.file(document.fileName),
12361241
line: position.line + 1,
@@ -1240,7 +1245,7 @@ namespace ComputeContextRequestArgs {
12401245
tokenBudget: context.tokenBudget ?? 7 * 1024,
12411246
neighborFiles: neighborFiles !== undefined && neighborFiles.length > 0 ? neighborFiles : undefined,
12421247
clientSideRunnableResults: clientSideRunnableResults,
1243-
$traceId: context.requestId
1248+
$traceId: willLogRequestTelemetry ? context.requestId : undefined
12441249
};
12451250
}
12461251
}
@@ -1418,7 +1423,8 @@ export class LanguageContextServiceImpl implements ILanguageContextService, vsco
14181423
}
14191424
const neighborFiles: string[] = this.neighborFileModel.getNeighborFiles(document);
14201425
const timeBudget = this.cachePopulationTimeout;
1421-
const args: ComputeContextRequestArgs = ComputeContextRequestArgs.create(document, position, context, startTime, timeBudget, neighborFiles, contextRequestState?.server);
1426+
const willLogRequestTelemetry = this.telemetrySender.willLogRequestTelemetry(context);
1427+
const args: ComputeContextRequestArgs = ComputeContextRequestArgs.create(document, position, context, startTime, timeBudget, willLogRequestTelemetry, neighborFiles, contextRequestState?.server);
14221428
try {
14231429
const isDebugging = this.isDebugging;
14241430
const forDebugging: ContextItem[] | undefined = isDebugging ? [] : undefined;
@@ -1523,7 +1529,8 @@ export class LanguageContextServiceImpl implements ILanguageContextService, vsco
15231529
}
15241530
}
15251531

1526-
const args: ComputeContextRequestArgs = ComputeContextRequestArgs.create(document, position, context, startTime, timeBudget, neighborFiles, contextRequestState?.server);
1532+
const willLogRequestTelemetry = this.telemetrySender.willLogRequestTelemetry(context);
1533+
const args: ComputeContextRequestArgs = ComputeContextRequestArgs.create(document, position, context, startTime, timeBudget, willLogRequestTelemetry, neighborFiles, contextRequestState?.server);
15271534
try {
15281535
if (this.inflightRequest !== undefined) {
15291536
// We have an inflight request. Cancel it.

0 commit comments

Comments
 (0)