Wraps an async function with an OpenTelemetry span
Creates a new span, executes the provided function within the span context, and automatically handles span lifecycle (status, exceptions, ending).
Name of the span
Async function to wrap with span
Name of the tracer (default: 'default')
Promise resolving to the function result
const result = await withSpan('database-query', async () => { return await db.query('SELECT * FROM users')})// With custom tracer nameconst result = await withSpan( 'api-call', async () => fetch('https://api.example.com'), 'my-service') Copy
const result = await withSpan('database-query', async () => { return await db.query('SELECT * FROM users')})// With custom tracer nameconst result = await withSpan( 'api-call', async () => fetch('https://api.example.com'), 'my-service')
Wraps an async function with an OpenTelemetry span
Creates a new span, executes the provided function within the span context, and automatically handles span lifecycle (status, exceptions, ending).