(metadata?: {
success?: boolean
error?: string
})
| 655 | } |
| 656 | |
| 657 | export function endToolExecutionSpan(metadata?: { |
| 658 | success?: boolean |
| 659 | error?: string |
| 660 | }): void { |
| 661 | if (!isAnyTracingEnabled()) { |
| 662 | return |
| 663 | } |
| 664 | |
| 665 | const executionSpanContext = Array.from(activeSpans.values()) |
| 666 | .findLast(r => r.deref()?.attributes['span.type'] === 'tool.execution') |
| 667 | ?.deref() |
| 668 | |
| 669 | if (!executionSpanContext) { |
| 670 | return |
| 671 | } |
| 672 | |
| 673 | const duration = Date.now() - executionSpanContext.startTime |
| 674 | const attributes: Record<string, string | number | boolean> = { |
| 675 | duration_ms: duration, |
| 676 | } |
| 677 | |
| 678 | if (metadata) { |
| 679 | if (metadata.success !== undefined) attributes['success'] = metadata.success |
| 680 | if (metadata.error !== undefined) attributes['error'] = metadata.error |
| 681 | } |
| 682 | |
| 683 | executionSpanContext.span.setAttributes(attributes) |
| 684 | executionSpanContext.span.end() |
| 685 | |
| 686 | const spanId = getSpanId(executionSpanContext.span) |
| 687 | activeSpans.delete(spanId) |
| 688 | strongSpans.delete(spanId) |
| 689 | } |
| 690 | |
| 691 | export function endToolSpan(toolResult?: string, resultTokens?: number): void { |
| 692 | const toolSpanContext = toolContext.getStore() |
no test coverage detected