Class NoopOpenTelemetry

java.lang.Object
io.opentelemetry.extension.noopapi.NoopOpenTelemetry
All Implemented Interfaces:
io.opentelemetry.api.OpenTelemetry

public class NoopOpenTelemetry extends Object implements io.opentelemetry.api.OpenTelemetry
An implementation of OpenTelemetry that is completely no-op. Unlike OpenTelemetry.noop(), this implementation does not support in-process context propagation at all. This means that no objects are allocated nor ThreadLocals used in an application using this implementation. This can be a good option for use in frameworks shared across a large number of servers to introduce instrumentation without forcing overhead on any users of the framework. If such overhead is not a concern, always use either OpenTelemetry.noop(), OpenTelemetry.propagating(ContextPropagators), or the OpenTelemetry SDK.

The following code will fail because context is not mounted.


 try (Scope ignored = Context.current().with(Span.wrap(VALID_SPAN_CONTEXT).makeCurrent()) {
   assert Span.current().spanContext().equals(VALID_SPAN_CONTEXT);
 }
 

In most cases when instrumenting a library, the above pattern does not happen because Span.wrap(SpanContext) is primarily for use in remote propagators. The common pattern looks like


 Span span = tracer.spanBuilder().setAttribute(...).startSpan();
 try (Scope ignored = Context.current().with(span).makeCurrent()) {
   assert Span.current().spanContext().equals(SpanContext.getInvalid());
 }
 

The above will succeed both with the default implementation and this one, but with this implementation there will be no overhead at all.

  • Method Details

    • getInstance

      public static io.opentelemetry.api.OpenTelemetry getInstance()
    • getTracerProvider

      public io.opentelemetry.api.trace.TracerProvider getTracerProvider()
      Specified by:
      getTracerProvider in interface io.opentelemetry.api.OpenTelemetry
    • getMeterProvider

      public io.opentelemetry.api.metrics.MeterProvider getMeterProvider()
      Specified by:
      getMeterProvider in interface io.opentelemetry.api.OpenTelemetry
    • getPropagators

      public io.opentelemetry.context.propagation.ContextPropagators getPropagators()
      Specified by:
      getPropagators in interface io.opentelemetry.api.OpenTelemetry