Documentation / @zerotal/telemetry / withSpan
Function: withSpan()
withSpan<
T>(name,fn,options?):Promise<T>
Defined in: telemetry/src/withSpan.ts:33
Runs fn inside a named span using the global tracer registered by
TelemetryProvider. If no tracer is registered the callback runs normally
and receives a no-op span — no error is thrown.
Type Parameters
T
T
Parameters
name
string
fn
(span) => Promise<T>
options?
SpanOptions = {}
Returns
Promise<T>
Example
import { withSpan } from '@zerotal/telemetry';
async function processOrder(id: string) {
return withSpan('process-order', async (span) => {
span.setAttribute('order.id', id);
// ...
});
}