dd-trace
    Preparing search index...

    Interface Tracer

    Tracer provides an interface for creating Spans.

    interface Tracer {
        startActiveSpan<F extends (span: opentelemetry.Span) => unknown>(
            name: string,
            options?: SpanOptions,
            context?: Context,
            fn: F,
        ): ReturnType<F>;
        startActiveSpan<F extends (span: opentelemetry.Span) => unknown>(
            name: string,
            options: SpanOptions,
            fn: F,
        ): ReturnType<F>;
        startActiveSpan<F extends (span: opentelemetry.Span) => unknown>(
            name: string,
            fn: F,
        ): ReturnType<F>;
        startSpan(
            name: string,
            options?: SpanOptions,
            context?: Context,
        ): opentelemetry.Span;
    }

    Hierarchy

    • Tracer
      • Tracer
    Index

    Methods

    • 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.

      Type Parameters

      Parameters

      • name: string

        The name of the span

      • Optionaloptions: SpanOptions

        SpanOptions used for span creation

      • Optionalcontext: 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.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();
    • 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.

      Type Parameters

      Parameters

      • name: string

        The name of the span

      • options: SpanOptions

        SpanOptions 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.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();
    • 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.

      Type Parameters

      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.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();
    • Starts a new Span. Start the span without setting it on context.

      This method do NOT modify the current Context.

      Parameters

      • name: string

        The name of the span

      • Optionaloptions: SpanOptions

        SpanOptions used for span creation

      • Optionalcontext: Context

        Context to use to extract parent

      Returns opentelemetry.Span

      Span The newly created span

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