(span: Span, shape: CopilotOtelRequestShape)
| 500 | const INTERRUPT_WAIT_MS_THRESHOLD = 50 |
| 501 | |
| 502 | function applyRequestShape(span: Span, shape: CopilotOtelRequestShape): void { |
| 503 | if (shape.branchKind) { |
| 504 | span.setAttribute(TraceAttr.CopilotBranchKind, shape.branchKind) |
| 505 | span.setAttribute( |
| 506 | TraceAttr.CopilotSurface, |
| 507 | shape.branchKind === CopilotBranchKind.Workflow |
| 508 | ? CopilotSurface.Copilot |
| 509 | : CopilotSurface.Mothership |
| 510 | ) |
| 511 | } |
| 512 | if (shape.mode) span.setAttribute(TraceAttr.CopilotMode, shape.mode) |
| 513 | if (shape.model) span.setAttribute(TraceAttr.GenAiRequestModel, shape.model) |
| 514 | if (shape.provider) span.setAttribute(TraceAttr.GenAiSystem, shape.provider) |
| 515 | if (typeof shape.createNewChat === 'boolean') { |
| 516 | span.setAttribute(TraceAttr.CopilotChatIsNew, shape.createNewChat) |
| 517 | } |
| 518 | if (typeof shape.prefetch === 'boolean') { |
| 519 | span.setAttribute(TraceAttr.CopilotPrefetch, shape.prefetch) |
| 520 | } |
| 521 | if (typeof shape.fileAttachmentsCount === 'number') { |
| 522 | span.setAttribute(TraceAttr.CopilotFileAttachmentsCount, shape.fileAttachmentsCount) |
| 523 | } |
| 524 | if (typeof shape.resourceAttachmentsCount === 'number') { |
| 525 | span.setAttribute(TraceAttr.CopilotResourceAttachmentsCount, shape.resourceAttachmentsCount) |
| 526 | } |
| 527 | if (typeof shape.contextsCount === 'number') { |
| 528 | span.setAttribute(TraceAttr.CopilotContextsCount, shape.contextsCount) |
| 529 | } |
| 530 | if (typeof shape.commandsCount === 'number') { |
| 531 | span.setAttribute(TraceAttr.CopilotCommandsCount, shape.commandsCount) |
| 532 | } |
| 533 | if (typeof shape.pendingStreamWaitMs === 'number') { |
| 534 | span.setAttribute(TraceAttr.CopilotPendingStreamWaitMs, shape.pendingStreamWaitMs) |
| 535 | const interrupted = |
| 536 | typeof shape.interruptedPriorStream === 'boolean' |
| 537 | ? shape.interruptedPriorStream |
| 538 | : shape.pendingStreamWaitMs > INTERRUPT_WAIT_MS_THRESHOLD |
| 539 | span.setAttribute(TraceAttr.CopilotInterruptedPriorStream, interrupted) |
| 540 | } else if (typeof shape.interruptedPriorStream === 'boolean') { |
| 541 | span.setAttribute(TraceAttr.CopilotInterruptedPriorStream, shape.interruptedPriorStream) |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | export async function withCopilotOtelContext<T>( |
| 546 | scope: CopilotOtelScope, |
no outgoing calls
no test coverage detected