OpenTelemetry SDK
    Preparing search index...

    Tracer provides an interface for creating Spans.

    1.0.0

    Implements

    Index
    startActiveSpan: {
        <F extends (span: Span) => unknown>(name: string, fn: F): ReturnType<F>;
        <F extends (span: Span) => unknown>(
            name: string,
            options: SpanOptions,
            fn: F,
        ): ReturnType<F>;
        <F extends (span: Span) => unknown>(
            name: string,
            options: SpanOptions,
            context: Context,
            fn: F,
        ): ReturnType<F>;
    }

    Starts a new Span and calls the given function passing it the created span as first argument. Additionally the new span gets set in context and this context is activated for the duration of the function call.

    Important: The callback function is responsible for calling span.end() to finish the span. Unlike some other OpenTelemetry implementations, the span is NOT automatically ended when the callback returns. If span.end() is not called, the span will never be exported and will be silently lost.

    The name of the span

    SpanOptions used for span creation

    Context to use to extract parent

    function called in the context of the span and receives the newly created span as an argument

    return value of fn

    const something = tracer.startActiveSpan('op', span => {
    try {
    do some work
    span.setStatus({code: SpanStatusCode.OK});
    return something;
    } catch (err) {
    span.setStatus({
    code: SpanStatusCode.ERROR,
    message: err.message,
    });
    throw err;
    } finally {
    span.end();
    }
    });
    const span = tracer.startActiveSpan('op', span => {
    try {
    do some work
    return span;
    } catch (err) {
    span.setStatus({
    code: SpanStatusCode.ERROR,
    message: err.message,
    });
    throw err;
    }
    });
    do some more work
    span.end();
    startSpan: (name: string, options?: SpanOptions, context?: Context) => Span

    Starts a new Span. Start the span without setting it on context.

    This method do NOT modify the current Context.

    Type Declaration

      • (name: string, options?: SpanOptions, context?: Context): Span
      • Parameters

        • name: string

          The name of the span

        • Optionaloptions: SpanOptions

          SpanOptions used for span creation

        • Optionalcontext: Context

          Context to use to extract parent

        Returns Span

        Span The newly created span

    const span = tracer.startSpan('op');
    span.setAttribute('key', 'value');
    span.end();
    • Starts a new Span and calls the given function passing it the created span as first argument. Additionally, the new span gets set in context and this context is activated for the duration of the function call. The span will be closed after the function has executed. If an exception occurs, it is recorded, the status is set to ERROR and the exception is rethrown.

      Type Parameters

      • F extends (span: Span) => ReturnType<F>

      Parameters

      • name: string

        The name of the span

      • fn: F

        function called in the context of the span and receives the newly created span as an argument

      Returns ReturnType<F>

      return value of fn

      const something = tracer.withActiveSpan('op', span => {
      // do some work
      });
      const something = await tracer.withActiveSpan('op', span => {
      // do some async work
      });
    • Starts a new Span and calls the given function passing it the created span as first argument. Additionally, the new span gets set in context and this context is activated for the duration of the function call. The span will be closed after the function has executed. If an exception occurs, it is recorded, the status is set to ERROR and the exception is rethrown.

      Type Parameters

      • F extends (span: Span) => ReturnType<F>

      Parameters

      • name: string

        The name of the span

      • options: SugaredSpanOptions

        SugaredSpanOptions used for span creation

      • fn: F

        function called in the context of the span and receives the newly created span as an argument

      Returns ReturnType<F>

      return value of fn

      const something = tracer.withActiveSpan('op', span => {
      // do some work
      });
      const something = await tracer.withActiveSpan('op', span => {
      // do some async work
      });
    • Starts a new Span and calls the given function passing it the created span as first argument. Additionally, the new span gets set in context and this context is activated for the duration of the function call. The span will be closed after the function has executed. If an exception occurs, it is recorded, the status is set to ERROR and the exception is rethrown.

      Type Parameters

      • F extends (span: Span) => ReturnType<F>

      Parameters

      • name: string

        The name of the span

      • options: SugaredSpanOptions

        SugaredSpanOptions used for span creation

      • context: Context

        Context to use to extract parent

      • fn: F

        function called in the context of the span and receives the newly created span as an argument

      Returns ReturnType<F>

      return value of fn

      const something = tracer.withActiveSpan('op', span => {
      // do some work
      });
      const something = await tracer.withActiveSpan('op', span => {
      // do some async work
      });
    • Starts a new Span and ends it after execution of fn without setting it on context. The span will be closed after the function has executed. If an exception occurs, it is recorded, the status is et to ERROR and rethrown.

      This method does NOT modify the current Context.

      Type Parameters

      • F extends (span: Span) => ReturnType<F>

      Parameters

      • name: string

        The name of the span

      • fn: F

        function called in the context of the span and receives the newly created span as an argument

      Returns ReturnType<F>

      Span The newly created span

      const something = tracer.withSpan('op', span => {
      // do some work
      });
      const something = await tracer.withSpan('op', span => {
      // do some async work
      });
    • Starts a new Span and ends it after execution of fn without setting it on context. The span will be closed after the function has executed. If an exception occurs, it is recorded, the status is et to ERROR and rethrown.

      This method does NOT modify the current Context.

      Type Parameters

      • F extends (span: Span) => ReturnType<F>

      Parameters

      • name: string

        The name of the span

      • options: SugaredSpanOptions

        SugaredSpanOptions used for span creation

      • fn: F

        function called in the context of the span and receives the newly created span as an argument

      Returns ReturnType<F>

      Span The newly created span

      const something = tracer.withSpan('op', span => {
      // do some work
      });
      const something = await tracer.withSpan('op', span => {
      // do some async work
      });
    • Starts a new Span and ends it after execution of fn without setting it on context. The span will be closed after the function has executed. If an exception occurs, it is recorded, the status is et to ERROR and rethrown.

      This method does NOT modify the current Context.

      Type Parameters

      • F extends (span: Span) => ReturnType<F>

      Parameters

      • name: string

        The name of the span

      • options: SugaredSpanOptions

        SugaredSpanOptions used for span creation

      • context: Context

        Context to use to extract parent

      • fn: F

        function called in the context of the span and receives the newly created span as an argument

      Returns ReturnType<F>

      Span The newly created span

      const something = tracer.withSpan('op', span => {
      // do some work
      });
      const something = await tracer.withSpan('op', span => {
      // do some async work
      });
    • Starts a new Span and ends it after execution of fn without setting it on context. The span will be closed after the function has executed. If an exception occurs, it is recorded, the status is et to ERROR and rethrown.

      This method does NOT modify the current Context.

      Type Parameters

      • F extends (span: Span) => ReturnType<F>

      Parameters

      • name: string

        The name of the span

      • options: SugaredSpanOptions

        SugaredSpanOptions used for span creation

      • context: Context

        Context to use to extract parent

      • fn: F

        function called in the context of the span and receives the newly created span as an argument

      Returns ReturnType<F>

      Span The newly created span

      const something = tracer.withSpan('op', span => {
      // do some work
      });
      const something = await tracer.withSpan('op', span => {
      // do some async work
      });