@@ -265,6 +265,11 @@ class TelemetrySender {
265
265
this . logService . logger . debug ( `TypeScript Copilot context speculative request: [${ context . requestId } - ${ originalRequestId } , numberOfItems: ${ numberOfItems } ]` ) ;
266
266
}
267
267
268
+ public willLogRequestTelemetry ( context : RequestContext ) : boolean {
269
+ const sampleTelemetry = RequestContext . getSampleTelemetry ( context ) ;
270
+ return sampleTelemetry === 1 || this . sendRequestTelemetryCounter % sampleTelemetry === 0 ;
271
+ }
272
+
268
273
public sendRequestTelemetry ( document : vscode . TextDocument , position : vscode . Position , context : RequestContext , data : ContextItemSummary , timeTaken : number , cacheState : { before : CacheState ; after : CacheState } | undefined ) : void {
269
274
const stats = data . stats ;
270
275
const nodePath = data ?. path ? JSON . stringify ( data . path ) : JSON . stringify ( [ 0 ] ) ;
@@ -1230,7 +1235,7 @@ type ComputeContextRequestArgs = {
1230
1235
$traceId ?: string ;
1231
1236
} ;
1232
1237
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 {
1234
1239
return {
1235
1240
file : vscode . Uri . file ( document . fileName ) ,
1236
1241
line : position . line + 1 ,
@@ -1240,7 +1245,7 @@ namespace ComputeContextRequestArgs {
1240
1245
tokenBudget : context . tokenBudget ?? 7 * 1024 ,
1241
1246
neighborFiles : neighborFiles !== undefined && neighborFiles . length > 0 ? neighborFiles : undefined ,
1242
1247
clientSideRunnableResults : clientSideRunnableResults ,
1243
- $traceId : context . requestId
1248
+ $traceId : willLogRequestTelemetry ? context . requestId : undefined
1244
1249
} ;
1245
1250
}
1246
1251
}
@@ -1418,7 +1423,8 @@ export class LanguageContextServiceImpl implements ILanguageContextService, vsco
1418
1423
}
1419
1424
const neighborFiles : string [ ] = this . neighborFileModel . getNeighborFiles ( document ) ;
1420
1425
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 ) ;
1422
1428
try {
1423
1429
const isDebugging = this . isDebugging ;
1424
1430
const forDebugging : ContextItem [ ] | undefined = isDebugging ? [ ] : undefined ;
@@ -1523,7 +1529,8 @@ export class LanguageContextServiceImpl implements ILanguageContextService, vsco
1523
1529
}
1524
1530
}
1525
1531
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 ) ;
1527
1534
try {
1528
1535
if ( this . inflightRequest !== undefined ) {
1529
1536
// We have an inflight request. Cancel it.
0 commit comments