Class GlobalOpenTelemetry


  • public final class GlobalOpenTelemetry
    extends Object
    A global singleton for the entrypoint to telemetry functionality for tracing, metrics and baggage.

    The global singleton can be retrieved by get(). The default for the returned OpenTelemetry, if none has been set via set(OpenTelemetry), will be created with any OpenTelemetryFactory, TracerProviderFactory or MeterProviderFactory found on the classpath, or otherwise will be default, with no-op behavior.

    If using the OpenTelemetry SDK, you may want to instantiate the OpenTelemetry to provide configuration, for example of Resource or Sampler. See OpenTelemetrySdk and OpenTelemetrySdk.builder for information on how to construct the SDK OpenTelemetry.

    See Also:
    TracerProvider, MeterProvider, ContextPropagators
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static OpenTelemetry get()
      Returns the registered global OpenTelemetry.
      static io.opentelemetry.api.metrics.Meter getMeter​(String instrumentationName)
      Deprecated.
      this will be removed soon in preparation for the initial otel release.
      static io.opentelemetry.api.metrics.Meter getMeter​(String instrumentationName, String instrumentationVersion)
      Deprecated.
      this will be removed soon in preparation for the initial otel release.
      static io.opentelemetry.api.metrics.MeterProvider getMeterProvider()
      Deprecated.
      this will be removed soon in preparation for the initial otel release.
      static io.opentelemetry.context.propagation.ContextPropagators getPropagators()
      Returns the globally registered ContextPropagators for remote propagation of a context.
      static io.opentelemetry.api.trace.Tracer getTracer​(String instrumentationName)
      Gets or creates a named tracer instance from the globally registered TracerProvider.
      static io.opentelemetry.api.trace.Tracer getTracer​(String instrumentationName, String instrumentationVersion)
      Gets or creates a named and versioned tracer instance from the globally registered TracerProvider.
      static io.opentelemetry.api.trace.TracerProvider getTracerProvider()
      Returns the globally registered TracerProvider.
      static void set​(OpenTelemetry openTelemetry)
      Sets the OpenTelemetry that should be the global instance.
      static void setPropagators​(io.opentelemetry.context.propagation.ContextPropagators propagators)
      Deprecated.
      this will be removed soon, create a new instance if necessary.
    • Method Detail

      • set

        public static void set​(OpenTelemetry openTelemetry)
        Sets the OpenTelemetry that should be the global instance. Future calls to get() will return the provided OpenTelemetry instance. This should be called once as early as possible in your application initialization logic, often in a static block in your main class.
      • getTracerProvider

        public static io.opentelemetry.api.trace.TracerProvider getTracerProvider()
        Returns the globally registered TracerProvider.
      • getTracer

        public static io.opentelemetry.api.trace.Tracer getTracer​(String instrumentationName)
        Gets or creates a named tracer instance from the globally registered TracerProvider.

        This is a shortcut method for getTracerProvider().get(instrumentationName)

        Parameters:
        instrumentationName - The name of the instrumentation library, not the name of the instrument*ed* library (e.g., "io.opentelemetry.contrib.mongodb"). Must not be null.
        Returns:
        a tracer instance.
      • getTracer

        public static io.opentelemetry.api.trace.Tracer getTracer​(String instrumentationName,
                                                                  String instrumentationVersion)
        Gets or creates a named and versioned tracer instance from the globally registered TracerProvider.

        This is a shortcut method for getTracerProvider().get(instrumentationName, instrumentationVersion)

        Parameters:
        instrumentationName - The name of the instrumentation library, not the name of the instrument*ed* library (e.g., "io.opentelemetry.contrib.mongodb"). Must not be null.
        instrumentationVersion - The version of the instrumentation library (e.g., "1.0.0").
        Returns:
        a tracer instance.
      • getMeterProvider

        @Deprecated
        public static io.opentelemetry.api.metrics.MeterProvider getMeterProvider()
        Deprecated.
        this will be removed soon in preparation for the initial otel release.
        Returns the globally registered MeterProvider.
      • getMeter

        @Deprecated
        public static io.opentelemetry.api.metrics.Meter getMeter​(String instrumentationName)
        Deprecated.
        this will be removed soon in preparation for the initial otel release.
        Gets or creates a named meter instance from the globally registered MeterProvider.

        This is a shortcut method for getMeterProvider().get(instrumentationName)

        Parameters:
        instrumentationName - The name of the instrumentation library, not the name of the instrument*ed* library.
        Returns:
        a tracer instance.
      • getMeter

        @Deprecated
        public static io.opentelemetry.api.metrics.Meter getMeter​(String instrumentationName,
                                                                  String instrumentationVersion)
        Deprecated.
        this will be removed soon in preparation for the initial otel release.
        Gets or creates a named and versioned meter instance from the globally registered MeterProvider.

        This is a shortcut method for getMeterProvider().get(instrumentationName, instrumentationVersion)

        Parameters:
        instrumentationName - The name of the instrumentation library, not the name of the instrument*ed* library.
        instrumentationVersion - The version of the instrumentation library.
        Returns:
        a tracer instance.
      • getPropagators

        public static io.opentelemetry.context.propagation.ContextPropagators getPropagators()
        Returns the globally registered ContextPropagators for remote propagation of a context.
      • setPropagators

        @Deprecated
        public static void setPropagators​(io.opentelemetry.context.propagation.ContextPropagators propagators)
        Deprecated.
        this will be removed soon, create a new instance if necessary.
        Sets the globally registered ContextPropagators for remote propagation of a context.