Skip to content

withSpan

withSpan<T>(tracer, name, attrs, fn): Promise<T>

Defined in: packages/core/src/telemetry/traces.ts:75

Wrap an async operation in an OTel span with attributes and automatic error recording.

T

Tracer

a valid Tracer instance (real OTel or no-op)

string

the span name

Record<string, string | number | boolean>

key-value attributes to set on the span

() => Promise<T>

async function to execute within the span

Promise<T>

the result of fn

tracer is a valid Tracer instance

span is ended after fn completes or throws

Safe — creates a new span per call