MCPcopy Index your code
hub / github.com/simstudioai/sim / applyRequestShape

Function applyRequestShape

apps/sim/lib/copilot/request/otel.ts:502–543  ·  view source on GitHub ↗
(span: Span, shape: CopilotOtelRequestShape)

Source from the content-addressed store, hash-verified

500const INTERRUPT_WAIT_MS_THRESHOLD = 50
501
502function 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
545export async function withCopilotOtelContext<T>(
546 scope: CopilotOtelScope,

Callers 1

startCopilotOtelRootFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected