Skip to main content
zerotal

Documentation


Documentation / @zerotal/telemetry / Tracer

Class: Tracer

Defined in: telemetry/src/Tracer.ts:31

Creates and manages spans. Normally one tracer lives for the lifetime of the process, registered via TelemetryProvider.

Example

const tracer = new Tracer({ exporter: new ConsoleExporter() });

await tracer.withSpan('do-work', async (span) => {
  span.setAttribute('work.type', 'heavy');
  await heavyWork();
});

Constructors

Constructor

new Tracer(options): Tracer

Defined in: telemetry/src/Tracer.ts:36

Parameters

options

TracerOptions

Returns

Tracer

Methods

withSpan()

withSpan<T>(name, fn, options?): Promise<T>

Defined in: telemetry/src/Tracer.ts:47

Runs fn inside a new span. The span is automatically ended and exported when fn resolves or throws. Child spans created with withSpan() inside fn will automatically be attached as children.

Type Parameters

T

T

Parameters

name

string

fn

(span) => Promise<T>

options?

SpanOptions = {}

Returns

Promise<T>


recordCompleted()

recordCompleted(name, durationMs, options?): Promise<void>

Defined in: telemetry/src/Tracer.ts:81

Record an already-completed unit of work as a span. Used to bridge synchronous framework events (which carry their own durationMs) into the trace pipeline: the span is back-dated by durationMs, ended, and exported immediately. It has no parent/active context — these spans represent self-contained, past work.

Parameters

name

string

durationMs

number

options?

SpanOptions & object = {}

Returns

Promise<void>


startSpan()

startSpan(name, options?): Span

Defined in: telemetry/src/Tracer.ts:96

Start a span manually. Caller is responsible for calling span.end().

Parameters

name

string

options?

SpanOptions = {}

Returns

Span


shutdown()

shutdown(): Promise<void>

Defined in: telemetry/src/Tracer.ts:105

Flush any pending spans and tear down the exporter.

Returns

Promise<void>