Interface ITracer

Interface for the distributed tracer.

Example

const tracer = new Tracer();

const span = tracer.startSpan('process-request', {
kind: 'server',
attributes: { 'gmi.id': 'gmi-123' },
});

try {
// Process request
span.addEvent('processing-started');
const result = await processRequest();
span.setAttribute('result.count', result.length);
span.setStatus('ok');
} catch (error) {
span.recordException(error);
span.setStatus('error', error.message);
} finally {
span.end();
}
interface ITracer {
    name: string;
    getCurrentContext(): undefined | TraceContext;
    startSpan(name, options?): ISpan;
    withSpan<T>(name, fn, options?): Promise<T>;
    inject<T>(carrier): T;
    extract(carrier): undefined | TraceContext;
    getSpan(spanId): undefined | ISpan;
    getActiveSpans(): ISpan[];
    addExporter(exporter): void;
    flush(): Promise<void>;
    getStats(): TracerStats;
    resetStats(): void;
    shutdown(): Promise<void>;
}

Implemented by

Methods

  • Wraps an async function with tracing.

    Type Parameters

    • T

    Parameters

    • name: string

      Span name

    • fn: ((span) => Promise<T>)

      Function to wrap

        • (span): Promise<T>
        • Parameters

          Returns Promise<T>

    • Optional options: SpanOptions

      Span options

    Returns Promise<T>

    Result of the function

  • Injects trace context into a carrier (for propagation).

    Type Parameters

    • T extends Record<string, string>

    Parameters

    • carrier: T

      Object to inject into

    Returns T

    The carrier with injected context

Properties

name: string

Gets the tracer name.