( hookEvent: string, hookName: string, numHooks: number, hookDefinitions: string, )
| 842 | * @returns The span (or a dummy span if tracing is disabled) |
| 843 | */ |
| 844 | export function startHookSpan( |
| 845 | hookEvent: string, |
| 846 | hookName: string, |
| 847 | numHooks: number, |
| 848 | hookDefinitions: string, |
| 849 | ): Span { |
| 850 | if (!isBetaTracingEnabled()) { |
| 851 | return trace.getActiveSpan() || getTracer().startSpan('dummy') |
| 852 | } |
| 853 | |
| 854 | const tracer = getTracer() |
| 855 | const parentSpanCtx = toolContext.getStore() ?? interactionContext.getStore() |
| 856 | |
| 857 | const attributes = createSpanAttributes('hook', { |
| 858 | hook_event: hookEvent, |
| 859 | hook_name: hookName, |
| 860 | num_hooks: numHooks, |
| 861 | hook_definitions: hookDefinitions, |
| 862 | }) |
| 863 | |
| 864 | const ctx = parentSpanCtx |
| 865 | ? trace.setSpan(otelContext.active(), parentSpanCtx.span) |
| 866 | : otelContext.active() |
| 867 | const span = tracer.startSpan('claude_code.hook', { attributes }, ctx) |
| 868 | |
| 869 | const spanId = getSpanId(span) |
| 870 | const spanContextObj: SpanContext = { |
| 871 | span, |
| 872 | startTime: Date.now(), |
| 873 | attributes, |
| 874 | } |
| 875 | activeSpans.set(spanId, new WeakRef(spanContextObj)) |
| 876 | strongSpans.set(spanId, spanContextObj) |
| 877 | |
| 878 | return span |
| 879 | } |
| 880 | |
| 881 | /** |
| 882 | * End a hook execution span with outcome metadata. |
no test coverage detected