Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Tracer

Tracer provides an interface for creating Spans and propagating context in-process.

Users may choose to use manual or automatic Context propagation. Because of that this class offers APIs to facilitate both usages.

Hierarchy

  • Tracer

Implemented by

Index

Methods

bind

  • bind<T>(target: T, context?: Span): T
  • Bind a span as the target's context or propagate the current one.

    Type parameters

    • T

    Parameters

    • target: T

      Any object to which a context need to be set

    • Optional context: Span

    Returns T

getCurrentSpan

  • getCurrentSpan(): Span | undefined
  • Returns the current Span from the current context if available.

    If there is no Span associated with the current context, null is returned.

    To install a Span to the current Context use Tracer.withSpan.

    Returns Span | undefined

    Span The currently active Span

startSpan

  • Starts a new Span. Start the span without setting it as the current span in this tracer's context.

    This method do NOT modify the current Context. To install a Span to the current Context use Tracer.withSpan.

    example
    const span = tracer.startSpan('op');
    span.setAttribute('key', 'value');
    span.end();

    Parameters

    • name: string

      The name of the span

    • Optional options: SpanOptions
    • Optional context: Context

    Returns Span

    Span The newly created span

withSpan

  • withSpan<T>(span: Span, fn: T): ReturnType<T>
  • Executes the function given by fn within the context provided by Span.

    This is a convenience method for creating spans attached to the tracer's context. Applications that need more control over the span lifetime should use Tracer.startSpan instead.

    example
    tracer.withSpan(span, () => {
        tracer.getCurrentSpan().addEvent("parent's event");
        doSomeOtherWork();  // Here "span" is the current Span.
    });

    Type parameters

    • T: (...args: unknown[]) => ReturnType<T>

    Parameters

    • span: Span

      The span that provides the context

    • fn: T

      The function to be executed inside the provided context

    Returns ReturnType<T>