Class GlobalOpenTelemetry
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:
-
TracerProviderContextPropagators
-
Method Summary
Modifier and TypeMethodDescriptionstatic OpenTelemetryget()Returns the registered globalOpenTelemetry.static MeterGets or creates a named meter instance from the globally registeredMeterProvider.static MeterProviderReturns the globally registeredMeterProvider.static io.opentelemetry.context.propagation.ContextPropagatorsReturns the globally registeredContextPropagatorsfor remote propagation of a context.static TracerGets or creates a named tracer instance from the globally registeredTracerProvider.static TracerGets or creates a named and versioned tracer instance from the globally registeredTracerProvider.static TracerProviderReturns the globally registeredTracerProvider.static MeterBuildermeterBuilder(String instrumentationName) Creates a MeterBuilder for a namedMeterinstance.static voidUnsets the globalOpenTelemetry.static voidset(OpenTelemetry openTelemetry) Sets theOpenTelemetrythat should be the global instance.static TracerBuildertracerBuilder(String instrumentationName) Creates a TracerBuilder for a namedTracerinstance.
-
Method Details
-
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
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. It should only be called once - an attempt to call it a second time will result in an error. If trying to set the globalOpenTelemetrymultiple times in tests, useresetForTest()between them.If you are using the OpenTelemetry SDK, you should generally use
OpenTelemetrySdk.builder().buildAndRegisterGlobal()instead of calling this method directly. -
getTracerProvider
Returns the globally registeredTracerProvider. -
getTracer
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
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.
-
tracerBuilder
Creates a TracerBuilder for a namedTracerinstance.This is a shortcut method for
get().tracerBuilder(instrumentationName)- Parameters:
instrumentationName- The name of the instrumentation library, not the name of the instrument*ed* library.- Returns:
- a TracerBuilder instance.
- Since:
- 1.4.0
-
getMeterProvider
Returns the globally registeredMeterProvider.- Since:
- 1.10.0
-
getMeter
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 (e.g., "io.opentelemetry.contrib.mongodb"). Must not be null.- Returns:
- a Meter instance.
- Since:
- 1.10.0
-
meterBuilder
Creates a MeterBuilder for a namedMeterinstance.This is a shortcut method for
get().meterBuilder(instrumentationName)- Parameters:
instrumentationName- The name of the instrumentation library, not the name of the instrument*ed* library.- Returns:
- a MeterBuilder instance.
- Since:
- 1.10.0
-
resetForTest
public static void resetForTest()Unsets the globalOpenTelemetry. This is only meant to be used from tests which need to reconfigureOpenTelemetry. -
getPropagators
public static io.opentelemetry.context.propagation.ContextPropagators getPropagators()Returns the globally registeredContextPropagatorsfor remote propagation of a context.
-