( decision?: string, source?: string, )
| 575 | } |
| 576 | |
| 577 | export function endToolBlockedOnUserSpan( |
| 578 | decision?: string, |
| 579 | source?: string, |
| 580 | ): void { |
| 581 | const blockedSpanContext = Array.from(activeSpans.values()) |
| 582 | .findLast( |
| 583 | r => r.deref()?.attributes['span.type'] === 'tool.blocked_on_user', |
| 584 | ) |
| 585 | ?.deref() |
| 586 | |
| 587 | if (!blockedSpanContext) { |
| 588 | return |
| 589 | } |
| 590 | |
| 591 | // End Perfetto span |
| 592 | if (blockedSpanContext.perfettoSpanId) { |
| 593 | endUserInputPerfettoSpan(blockedSpanContext.perfettoSpanId, { |
| 594 | decision, |
| 595 | source, |
| 596 | }) |
| 597 | } |
| 598 | |
| 599 | if (!isAnyTracingEnabled()) { |
| 600 | const spanId = getSpanId(blockedSpanContext.span) |
| 601 | activeSpans.delete(spanId) |
| 602 | strongSpans.delete(spanId) |
| 603 | return |
| 604 | } |
| 605 | |
| 606 | const duration = Date.now() - blockedSpanContext.startTime |
| 607 | const attributes: Record<string, string | number | boolean> = { |
| 608 | duration_ms: duration, |
| 609 | } |
| 610 | |
| 611 | if (decision) { |
| 612 | attributes['decision'] = decision |
| 613 | } |
| 614 | if (source) { |
| 615 | attributes['source'] = source |
| 616 | } |
| 617 | |
| 618 | blockedSpanContext.span.setAttributes(attributes) |
| 619 | blockedSpanContext.span.end() |
| 620 | |
| 621 | const spanId = getSpanId(blockedSpanContext.span) |
| 622 | activeSpans.delete(spanId) |
| 623 | strongSpans.delete(spanId) |
| 624 | } |
| 625 | |
| 626 | export function startToolExecutionSpan(): Span { |
| 627 | if (!isAnyTracingEnabled()) { |
no test coverage detected