()
| 624 | } |
| 625 | |
| 626 | export function startToolExecutionSpan(): Span { |
| 627 | if (!isAnyTracingEnabled()) { |
| 628 | return trace.getActiveSpan() || getTracer().startSpan('dummy') |
| 629 | } |
| 630 | |
| 631 | const tracer = getTracer() |
| 632 | const parentSpanCtx = toolContext.getStore() |
| 633 | |
| 634 | const attributes = createSpanAttributes('tool.execution') |
| 635 | |
| 636 | const ctx = parentSpanCtx |
| 637 | ? trace.setSpan(otelContext.active(), parentSpanCtx.span) |
| 638 | : otelContext.active() |
| 639 | const span = tracer.startSpan( |
| 640 | 'claude_code.tool.execution', |
| 641 | { attributes }, |
| 642 | ctx, |
| 643 | ) |
| 644 | |
| 645 | const spanId = getSpanId(span) |
| 646 | const spanContextObj: SpanContext = { |
| 647 | span, |
| 648 | startTime: Date.now(), |
| 649 | attributes, |
| 650 | } |
| 651 | activeSpans.set(spanId, new WeakRef(spanContextObj)) |
| 652 | strongSpans.set(spanId, spanContextObj) |
| 653 | |
| 654 | return span |
| 655 | } |
| 656 | |
| 657 | export function endToolExecutionSpan(metadata?: { |
| 658 | success?: boolean |
no test coverage detected