Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Tracer

Package version

Interface for 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

Index

Properties

active

active: boolean

Get the active status from tracer instance

activeTraceParams

activeTraceParams: TraceParams

A configuration object for trace parameters

currentRootSpan

currentRootSpan: Span

Get and set the currentRootSpan to tracer instance

eventListeners

eventListeners: SpanEventListener[]

Get the eventListeners from tracer instance

logger

logger: Logger

A configuration for starting the tracer

propagation

propagation: Propagation

A propagation instance

sampler

sampler: Sampler

A sampler that will decide if the span will be sampled or not

Methods

bind

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

    Type parameters

    • T

    Parameters

    • target: T

      Any object to which a scope need to be set

    • Optional span: Span

    Returns T

clearCurrentTrace

  • clearCurrentTrace(): void
  • Clear the currentRootSpan from tracer instance

    Returns void

getBinaryFormat

getCurrentSpan

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

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

    Returns Span | null

    Span The currently active Span

getHttpTextFormat

  • Returns the HttpTextFormat interface which can inject/extract Spans.

    If no tracer implementation is provided, this defaults to the W3C Trace Context HTTP text format ({@link HttpTraceContext}). For more details see W3C Trace Context.

    Returns HttpTextFormat

onEndSpan

  • onEndSpan(span: Span): void
  • Happens when a span is ended

    Parameters

    Returns void

onStartSpan

  • onStartSpan(span: Span): void
  • Happens when a span is started

    Parameters

    Returns void

recordSpanData

  • recordSpanData(span: Span): void
  • Send a pre-populated span object to the exporter. Sampling and recording decisions as well as other collection optimizations are the responsibility of a caller.

    todo:

    Pending API discussion. Revisit if Span or SpanData should be passed in here once this is sorted out.

    Parameters

    • span: Span

      Span Data to be reported to all exporters.

    Returns void

registerSpanEventListener

  • Register a OnEndSpanEventListener on the tracer instance

    Parameters

    Returns void

setCurrentRootSpan

  • setCurrentRootSpan(root: Span): void
  • Sets the current root span.

    Parameters

    Returns void

start

  • Start a tracer instance

    Parameters

    Returns this

    A tracer instance started

startChildSpan

  • Start a new Span instance to the currentRootSpan

    Parameters

    Returns Span

    The new Span instance started

startRootSpan

  • Start a new RootSpan to currentRootSpan

    Type parameters

    • T

    Parameters

    • options: TraceOptions

      Options for tracer instance

    • fn: function

      Callback function

        • Parameters

          Returns T

    Returns T

    The callback return

startSpan

  • Starts a new Span.

    Parameters

    • name: string

      The name of the span

    • Optional options: SpanOptions

    Returns Span

    Span The newly created span

stop

  • stop(): this
  • Stop the tracer instance

    Returns this

unregisterSpanEventListener

  • Unregisters an end span event listener.

    Parameters

    Returns void

withSpan

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

    example

    tracer.withSpan(span, function() { ... });

    Type parameters

    • T: function

    Parameters

    • span: Span

      The span that provides the context

    • fn: T

      The function to be executed inside the provided context

    Returns ReturnType<T>

wrap

  • Binds the trace context to the given function. This is necessary in order to create child spans correctly in functions that are called asynchronously (for example, in a network response handler).

    Type parameters

    • T

    Parameters

    • fn: Func<T>

      A function to which to bind the trace context.

    Returns Func<T>

wrapEmitter

  • Binds the trace context to the given event emitter. This is necessary in order to create child spans correctly in event handlers.

    Parameters

    • emitter: NodeJsEventEmitter

      An event emitter whose handlers should have the trace context binded to them.

    Returns void

Generated using TypeDoc