Class BaseTracer

  • Direct Known Subclasses:
    DatabaseClientTracer, HttpClientTracer, HttpServerTracer, RpcClientTracer, RpcServerTracer

    public abstract class BaseTracer
    extends Object
    Base class for all instrumentation specific tracer implementations.

    Tracers should not use Span directly in their public APIs: ideally all lifecycle methods (ex. start/end methods) should return/accept Context.

    The BaseTracer offers several startSpan() utility methods for creating bare spans without any attributes. If you want to provide some additional attributes on span start please consider writing your own specific startSpan() method in the your tracer.

    When constructing Spans tracers should set all attributes available during construction on a SpanBuilder instead of a Span. This way SpanProcessors are able to see those attributes in the onStart() method and can freely read/modify them.

    • Constructor Detail

      • BaseTracer

        public BaseTracer()
      • BaseTracer

        @Deprecated
        public BaseTracer​(io.opentelemetry.api.trace.Tracer tracer)
        Deprecated.
        prefer to pass in an OpenTelemetry instance, instead.
        Prefer to pass in an OpenTelemetry instance, rather than just a Tracer, so you don't have to use the GlobalOpenTelemetry Propagator instance.
      • BaseTracer

        public BaseTracer​(io.opentelemetry.api.OpenTelemetry openTelemetry)
    • Method Detail

      • getPropagators

        public io.opentelemetry.context.propagation.ContextPropagators getPropagators()
      • startSpan

        public io.opentelemetry.context.Context startSpan​(Class<?> clazz)
      • startSpan

        public io.opentelemetry.context.Context startSpan​(Method method)
      • startSpan

        public io.opentelemetry.context.Context startSpan​(String spanName)
      • startSpan

        public io.opentelemetry.context.Context startSpan​(String spanName,
                                                          io.opentelemetry.api.trace.SpanKind kind)
      • startSpan

        public io.opentelemetry.context.Context startSpan​(io.opentelemetry.context.Context parentContext,
                                                          String spanName,
                                                          io.opentelemetry.api.trace.SpanKind kind)
      • spanNameForMethod

        public String spanNameForMethod​(Method method)
        This method is used to generate an acceptable span (operation) name based on a given method reference. Anonymous classes are named based on their parent.
      • spanNameForClass

        public String spanNameForClass​(Class<?> clazz)
        This method is used to generate an acceptable span (operation) name based on a given class reference. Anonymous classes are named based on their parent.
      • end

        public void end​(io.opentelemetry.context.Context context)
      • end

        public void end​(io.opentelemetry.context.Context context,
                        long endTimeNanos)
      • end

        @Deprecated
        public void end​(io.opentelemetry.api.trace.Span span)
        Deprecated.
        Use end(Context) instead.
        End span.
      • end

        @Deprecated
        public void end​(io.opentelemetry.api.trace.Span span,
                        long endTimeNanos)
        Deprecated.
        Use end(Context, long) instead.
        End span.
      • endExceptionally

        public void endExceptionally​(io.opentelemetry.context.Context context,
                                     Throwable throwable)
      • endExceptionally

        public void endExceptionally​(io.opentelemetry.context.Context context,
                                     Throwable throwable,
                                     long endTimeNanos)
      • addThrowable

        public void addThrowable​(io.opentelemetry.api.trace.Span span,
                                 Throwable throwable)
      • extractWithGlobalPropagators

        @Deprecated
        public static <C> io.opentelemetry.context.Context extractWithGlobalPropagators​(C carrier,
                                                                                        io.opentelemetry.context.propagation.TextMapGetter<C> getter)
        Deprecated.
        We should eliminate all static usages so we can use the non-global propagators.
        Do extraction with the propagators from the GlobalOpenTelemetry instance. Not recommended.
      • extract

        public <C> io.opentelemetry.context.Context extract​(C carrier,
                                                            io.opentelemetry.context.propagation.TextMapGetter<C> getter)
      • getCurrentServerSpan

        public static io.opentelemetry.api.trace.Span getCurrentServerSpan()
        Returns span of type SERVER from the current context or null if not found.
      • getCurrentServerSpan

        public static io.opentelemetry.api.trace.Span getCurrentServerSpan​(io.opentelemetry.context.Context context)
        Returns span of type SERVER from the given context or null if not found.