Skip to main content

Function: withSpanSync()

withSpanSync<T>(name, fn, options?): T

Defined in: src/observability/tracer.ts:275

Wraps a synchronous operation in a span.

Type Parameters

T

Parameters

name

string

Span name

fn

() => T

Synchronous function to execute

options?

WithSpanOptions

Optional span configuration

Returns

T

Result of the wrapped function

Remarks

Similar to withSpan but for purely synchronous operations. Does not create a Promise overhead.

Example

// Sync operation
const result = withSpanSync('parseJson', () => {
return JSON.parse(jsonString);
});

// With attributes
const hash = withSpanSync(
'computeHash',
() => crypto.createHash('sha256').update(data).digest('hex'),
{ attributes: { 'hash.algorithm': 'sha256' } }
);

Since

0.1.0