Class GlobalOpenTelemetry
- java.lang.Object
-
- io.opentelemetry.api.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 returnedOpenTelemetry, if none has been set viaset(OpenTelemetry), will be created with anyOpenTelemetryFactory,TracerProviderFactoryorMeterProviderFactoryfound on the classpath, or otherwise will be default, with no-op behavior.If using the OpenTelemetry SDK, you may want to instantiate the
OpenTelemetryto provide configuration, for example ofResourceorSampler. SeeOpenTelemetrySdkandOpenTelemetrySdk.builderfor information on how to construct the SDKOpenTelemetry.- See Also:
TracerProvider,MeterProvider,ContextPropagators
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static OpenTelemetryget()Returns the registered globalOpenTelemetry.static io.opentelemetry.api.metrics.MetergetMeter(String instrumentationName)Deprecated.this will be removed soon in preparation for the initial otel release.static io.opentelemetry.api.metrics.MetergetMeter(String instrumentationName, String instrumentationVersion)Deprecated.this will be removed soon in preparation for the initial otel release.static io.opentelemetry.api.metrics.MeterProvidergetMeterProvider()Deprecated.this will be removed soon in preparation for the initial otel release.static io.opentelemetry.context.propagation.ContextPropagatorsgetPropagators()Returns the globally registeredContextPropagatorsfor remote propagation of a context.static io.opentelemetry.api.trace.TracergetTracer(String instrumentationName)Gets or creates a named tracer instance from the globally registeredTracerProvider.static io.opentelemetry.api.trace.TracergetTracer(String instrumentationName, String instrumentationVersion)Gets or creates a named and versioned tracer instance from the globally registeredTracerProvider.static io.opentelemetry.api.trace.TracerProvidergetTracerProvider()Returns the globally registeredTracerProvider.static voidset(OpenTelemetry openTelemetry)Sets theOpenTelemetrythat should be the global instance.static voidsetPropagators(io.opentelemetry.context.propagation.ContextPropagators propagators)Deprecated.this will be removed soon, create a new instance if necessary.
-
-
-
Method Detail
-
get
public static OpenTelemetry get()
Returns the registered globalOpenTelemetry. If no call toset(OpenTelemetry)has been made so far, a defaultOpenTelemetrycomposed of functionality anyOpenTelemetryFactory,TracerProviderFactoryorMeterProviderFactory, found on the classpath, or otherwise will be default, with no-op behavior.- Throws:
IllegalStateException- if a provider has been specified by system property using the interface FQCN but the specified provider cannot be found.
-
set
public static void set(OpenTelemetry openTelemetry)
Sets theOpenTelemetrythat should be the global instance. Future calls toget()will return the providedOpenTelemetryinstance. This should be called once as early as possible in your application initialization logic, often in astaticblock in your main class.
-
getTracerProvider
public static io.opentelemetry.api.trace.TracerProvider getTracerProvider()
Returns the globally registeredTracerProvider.
-
getTracer
public static io.opentelemetry.api.trace.Tracer getTracer(String instrumentationName)
Gets or creates a named tracer instance from the globally registeredTracerProvider.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 registeredTracerProvider.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 registeredMeterProvider.
-
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 registeredMeterProvider.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 registeredMeterProvider.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 registeredContextPropagatorsfor 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 registeredContextPropagatorsfor remote propagation of a context.
-
-