MCPcopy
hub / github.com/codeaashu/claude-code / startLLMRequestPerfettoSpan

Function startLLMRequestPerfettoSpan

src/utils/telemetry/perfettoTracing.ts:425–463  ·  view source on GitHub ↗
(args: {
  model: string
  promptTokens?: number
  messageId?: string
  isSpeculative?: boolean
  querySource?: string
})

Source from the content-addressed store, hash-verified

423 * Start an API call span
424 */
425export function startLLMRequestPerfettoSpan(args: {
426 model: string
427 promptTokens?: number
428 messageId?: string
429 isSpeculative?: boolean
430 querySource?: string
431}): string {
432 if (!isEnabled) return ''
433
434 const spanId = generateSpanId()
435 const agentInfo = getCurrentAgentInfo()
436
437 pendingSpans.set(spanId, {
438 name: 'API Call',
439 category: 'api',
440 startTime: getTimestamp(),
441 agentInfo,
442 args: {
443 model: args.model,
444 prompt_tokens: args.promptTokens,
445 message_id: args.messageId,
446 is_speculative: args.isSpeculative ?? false,
447 query_source: args.querySource,
448 },
449 })
450
451 // Emit begin event
452 events.push({
453 name: 'API Call',
454 cat: 'api',
455 ph: 'B',
456 ts: pendingSpans.get(spanId)!.startTime,
457 pid: agentInfo.processId,
458 tid: agentInfo.threadId,
459 args: pendingSpans.get(spanId)!.args,
460 })
461
462 return spanId
463}
464
465/**
466 * End an API call span with response metadata

Callers 1

startLLMRequestSpanFunction · 0.85

Calls 6

generateSpanIdFunction · 0.85
getCurrentAgentInfoFunction · 0.85
getTimestampFunction · 0.85
getMethod · 0.65
setMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected