Class: TracingManager

Defined in: tracing/manager.ts:55

Manages distributed tracing for agent operations

Example

const tracing = new TracingManager({
  serviceName: 'my-agent',
  defaultAttributes: { environment: 'production' },
});

// Start a trace
const traceId = tracing.startTrace();

// Create spans
const span = tracing.startSpan({ name: 'process-request' });
span.attributes['request.id'] = '123';

// End span and trace
tracing.endSpan(span.spanId, { status: 'ok' });
const trace = tracing.endTrace(traceId);

Implements

Constructors

Constructor

new TracingManager(options?): TracingManager;

Defined in: tracing/manager.ts:77

Parameters

Parameter Type
options TracingManagerOptions

Returns

TracingManager

Methods

addSpanEvent()

addSpanEvent(
   spanId, 
   name, 
   attributes?): void;

Defined in: tracing/manager.ts:358

Add an event to a span

Parameters

Parameter Type Description
spanId string Span ID
name string Event name
attributes? SpanAttributes Event attributes

Returns

void

Implementation of

TracingManagerInterface.addSpanEvent

clear()

clear(): void;

Defined in: tracing/manager.ts:539

Clear all traces and spans

Returns

void

clearTrace()

clearTrace(traceId): boolean;

Defined in: tracing/manager.ts:178

Clear a trace from memory

Parameters

Parameter Type
traceId string

Returns

boolean

endSpan()

endSpan(spanId, options?): Span | undefined;

Defined in: tracing/manager.ts:283

End a span

Parameters

Parameter Type Description
spanId string Span ID to end
options? EndSpanOptions End options

Returns

Span | undefined

Ended span or undefined if not found

Implementation of

TracingManagerInterface.endSpan

endTrace()

endTrace(traceId): Trace | undefined;

Defined in: tracing/manager.ts:131

End a trace and optionally export it

Parameters

Parameter Type Description
traceId string Trace ID to end

Returns

Trace | undefined

Completed trace or undefined if not found

Implementation of

TracingManagerInterface.endTrace

export()

export(traceId): Promise<void>;

Defined in: tracing/manager.ts:490

Manually export a trace

Parameters

Parameter Type
traceId string

Returns

Promise<void>

getActiveTraces()

getActiveTraces(): Trace[];

Defined in: tracing/manager.ts:171

Get all active traces

Returns

Trace[]

getCurrentContext()

getCurrentContext(): SpanContext | undefined;

Defined in: tracing/manager.ts:337

Get current span context for propagation

Returns

SpanContext | undefined

getCurrentSpan()

getCurrentSpan(): Span | undefined;

Defined in: tracing/manager.ts:328

Get the current active span

Returns

Span | undefined

Implementation of

TracingManagerInterface.getCurrentSpan

getSpan()

getSpan(spanId): Span | undefined;

Defined in: tracing/manager.ts:321

Get a span by ID

Parameters

Parameter Type
spanId string

Returns

Span | undefined

getStats()

getStats(): {
  activeSpans: number;
  activeTraces: number;
  totalSpans: number;
};

Defined in: tracing/manager.ts:524

Get tracing statistics

Returns

{
  activeSpans: number;
  activeTraces: number;
  totalSpans: number;
}
Name Type Defined in
activeSpans number tracing/manager.ts:527
activeTraces number tracing/manager.ts:525
totalSpans number tracing/manager.ts:526

getTrace()

getTrace(traceId): Trace | undefined;

Defined in: tracing/manager.ts:164

Get a trace by ID

Parameters

Parameter Type
traceId string

Returns

Trace | undefined

Implementation of

TracingManagerInterface.getTrace

onEvent()

onEvent(handler): () => void;

Defined in: tracing/manager.ts:445

Subscribe to tracing events

Parameters

Parameter Type Description
handler TracingEventHandler Event handler

Returns

Unsubscribe function

() => void

recordError()

recordError(spanId, error): void;

Defined in: tracing/manager.ts:414

Record an error on a span

Parameters

Parameter Type Description
spanId string Span ID
error Error Error to record

Returns

void

setSpanAttributes()

setSpanAttributes(spanId, attributes): void;

Defined in: tracing/manager.ts:384

Set attributes on a span

Parameters

Parameter Type Description
spanId string Span ID
attributes SpanAttributes Attributes to set

Returns

void

Implementation of

TracingManagerInterface.setSpanAttributes

setSpanStatus()

setSpanStatus(
   spanId, 
   status, 
   message?): void;

Defined in: tracing/manager.ts:398

Set span status

Parameters

Parameter Type Description
spanId string Span ID
status SpanStatus Status
message? string Optional status message

Returns

void

Implementation of

TracingManagerInterface.setSpanStatus

startSpan()

startSpan(options): Span;

Defined in: tracing/manager.ts:201

Start a new span

Parameters

Parameter Type Description
options StartSpanOptions Span options

Returns

Span

Created span

Implementation of

TracingManagerInterface.startSpan

startTrace()

startTrace(attributes?): string;

Defined in: tracing/manager.ts:104

Start a new trace

Parameters

Parameter Type Description
attributes? SpanAttributes Additional trace-level attributes

Returns

string

Trace ID

Implementation of

TracingManagerInterface.startTrace