(args: {
model: string
promptTokens?: number
messageId?: string
isSpeculative?: boolean
querySource?: string
})
| 423 | * Start an API call span |
| 424 | */ |
| 425 | export 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 |
no test coverage detected