Package io.opentelemetry.api
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.If using the OpenTelemetry SDK, you may want to instantiate the
OpenTelemetry
to provide configuration, for example ofResource
orSampler
. SeeOpenTelemetrySdk
andOpenTelemetrySdk.builder
for information on how to construct the SDKOpenTelemetry
.- See Also:
TracerProvider
,ContextPropagators
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static OpenTelemetry
get()
Returns the registered globalOpenTelemetry
.static io.opentelemetry.context.propagation.ContextPropagators
getPropagators()
Returns the globally registeredContextPropagators
for remote propagation of a context.static Tracer
getTracer(String instrumentationName)
Gets or creates a named tracer instance from the globally registeredTracerProvider
.static Tracer
getTracer(String instrumentationName, String instrumentationVersion)
Gets or creates a named and versioned tracer instance from the globally registeredTracerProvider
.static TracerProvider
getTracerProvider()
Returns the globally registeredTracerProvider
.static void
set(OpenTelemetry openTelemetry)
Sets theOpenTelemetry
that should be the global instance.
-
-
-
Method Detail
-
get
public static OpenTelemetry get()
Returns the registered globalOpenTelemetry
.- 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 theOpenTelemetry
that should be the global instance. Future calls toget()
will return the providedOpenTelemetry
instance. This should be called once as early as possible in your application initialization logic, often in astatic
block in your main class.
-
getTracerProvider
public static TracerProvider getTracerProvider()
Returns the globally registeredTracerProvider
.
-
getTracer
public static 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 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.
-
getPropagators
public static io.opentelemetry.context.propagation.ContextPropagators getPropagators()
Returns the globally registeredContextPropagators
for remote propagation of a context.
-
-