MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / executeInSpan

Function executeInSpan

source code/utils/telemetry/sessionTracing.ts:790–835  ·  view source on GitHub ↗
(
  spanName: string,
  fn: (span: Span) => Promise<T>,
  attributes?: Record<string, string | number | boolean>,
)

Source from the content-addressed store, hash-verified

788}
789
790export async function executeInSpan<T>(
791 spanName: string,
792 fn: (span: Span) => Promise<T>,
793 attributes?: Record<string, string | number | boolean>,
794): Promise<T> {
795 if (!isAnyTracingEnabled()) {
796 return fn(trace.getActiveSpan() || getTracer().startSpan('dummy'))
797 }
798
799 const tracer = getTracer()
800 const parentSpanCtx = toolContext.getStore() ?? interactionContext.getStore()
801
802 const finalAttributes = createSpanAttributes('tool', {
803 ...attributes,
804 })
805
806 const ctx = parentSpanCtx
807 ? trace.setSpan(otelContext.active(), parentSpanCtx.span)
808 : otelContext.active()
809 const span = tracer.startSpan(spanName, { attributes: finalAttributes }, ctx)
810
811 const spanId = getSpanId(span)
812 const spanContextObj: SpanContext = {
813 span,
814 startTime: Date.now(),
815 attributes: finalAttributes,
816 }
817 activeSpans.set(spanId, new WeakRef(spanContextObj))
818 strongSpans.set(spanId, spanContextObj)
819
820 try {
821 const result = await fn(span)
822 span.end()
823 activeSpans.delete(spanId)
824 strongSpans.delete(spanId)
825 return result
826 } catch (error) {
827 if (error instanceof Error) {
828 span.recordException(error)
829 }
830 span.end()
831 activeSpans.delete(spanId)
832 strongSpans.delete(spanId)
833 throw error
834 }
835}
836
837/**
838 * Start a hook execution span.

Callers

nothing calls this directly

Calls 8

isAnyTracingEnabledFunction · 0.85
getTracerFunction · 0.85
createSpanAttributesFunction · 0.85
getSpanIdFunction · 0.85
activeMethod · 0.80
setMethod · 0.80
deleteMethod · 0.80
endMethod · 0.45

Tested by

no test coverage detected