Top Description Inners Fields Constructors Methods
io.opentelemetry.api

public final Class GlobalOpenTelemetry

extends Object
Class Inheritance
Annotations
@SuppressWarnings:StaticAssignmentOfThrowable
Imports
io.opentelemetry.api.internal.ConfigUtil, .GuardedBy, io.opentelemetry.api.logs.LoggerProvider, io.opentelemetry.api.metrics.Meter, .MeterBuilder, .MeterProvider, io.opentelemetry.api.trace.Tracer, .TracerBuilder, .TracerProvider, io.opentelemetry.context.propagation.ContextPropagators, java.lang.reflect.InvocationTargetException, .Method, java.util.logging.Level, .Logger, javax.annotation.Nullable, javax.annotation.concurrent.ThreadSafe

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 of Resource or Sampler. See OpenTelemetrySdk and OpenTelemetrySdk.builder for information on how to construct the SDK's OpenTelemetry implementation.

Warning

Due to the inherent complications around initialization order involving this class and its single global instance, we strongly recommend *not* using GlobalOpenTelemetry unless you have a use-case that absolutely requires it. Please favor using instances of OpenTelemetry wherever possible.

If you are using the OpenTelemetry javaagent, it is generally best to only call GlobalOpenTelemetry.get() once, and then pass the resulting reference where you need to use it.

See Also
TracerProvider, ContextPropagators

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
GlobalOpenTelemetry.ObfuscatedOpenTelemetry

Static global instances are obfuscated when they are returned from the API to prevent users from casting them to their SDK-specific implementation.

Field Summary

Modifier and TypeField and Description
private static final String
private static volatile GlobalOpenTelemetry.ObfuscatedOpenTelemetry
private static final Logger
private static final Object
private static Throwable

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static OpenTelemetry
get()

Returns the registered global OpenTelemetry.

public static Meter

Returns:

a Meter instance.
getMeter
(String
A name uniquely identifying the instrumentation scope, such as the instrumentation library, package, or fully qualified class name. Must not be null.
instrumentationScopeName
)

Gets or creates a named meter instance from the globally registered MeterProvider.

public static MeterProvider
getMeterProvider()

Returns the globally registered MeterProvider.

public static ContextPropagators
getPropagators()

Returns the globally registered ContextPropagators for remote propagation of a context.

public static Tracer

Returns:

a tracer instance.
getTracer
(String
A name uniquely identifying the instrumentation scope, such as the instrumentation library, package, or fully qualified class name. Must not be null.
instrumentationScopeName
)

Gets or creates a named tracer instance from the globally registered TracerProvider.

public static Tracer

Returns:

a tracer instance.
getTracer
(String
A name uniquely identifying the instrumentation scope, such as the instrumentation library, package, or fully qualified class name. Must not be null.
instrumentationScopeName
,
String
The version of the instrumentation scope (e.g., "1.0.0").
instrumentationScopeVersion
)

Gets or creates a named and versioned tracer instance from the globally registered TracerProvider.

public static TracerProvider
getTracerProvider()

Returns the globally registered TracerProvider.

private static OpenTelemetry
public static MeterBuilder

Returns:

a MeterBuilder instance.
meterBuilder
(String
A name uniquely identifying the instrumentation scope, such as the instrumentation library, package, or fully qualified class name. Must not be null.
instrumentationScopeName
)

Creates a MeterBuilder for a named Meter instance.

public static void
resetForTest()

Unsets the global OpenTelemetry.

public static void
set(OpenTelemetry openTelemetry)

Sets the OpenTelemetry that should be the global instance.

public static TracerBuilder

Returns:

a TracerBuilder instance.
tracerBuilder
(String
A name uniquely identifying the instrumentation scope, such as the instrumentation library, package, or fully qualified class name. Must not be null.
instrumentationScopeName
)

Creates a TracerBuilder for a named Tracer instance.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

GLOBAL_AUTOCONFIGURE_ENABLED_PROPERTYback to summary
private static final String GLOBAL_AUTOCONFIGURE_ENABLED_PROPERTY
globalOpenTelemetryback to summary
private static volatile GlobalOpenTelemetry.ObfuscatedOpenTelemetry globalOpenTelemetry
Annotations
@SuppressWarnings:NonFinalStaticField
@Nullable
loggerback to summary
private static final Logger logger
mutexback to summary
private static final Object mutex
setGlobalCallerback to summary
private static Throwable setGlobalCaller
Annotations
@SuppressWarnings:NonFinalStaticField
@GuardedBy:mutex
@Nullable

Constructor Detail

GlobalOpenTelemetryback to summary
private GlobalOpenTelemetry()

Method Detail

getback to summary
public static OpenTelemetry get()

Returns the registered global OpenTelemetry.

Exceptions
IllegalStateException:
if a provider has been specified by system property using the interface FQCN but the specified provider cannot be found.
getMeterback to summary
public static Meter getMeter(String instrumentationScopeName)

Gets or creates a named meter instance from the globally registered MeterProvider.

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

Parameters
instrumentationScopeName:String

A name uniquely identifying the instrumentation scope, such as the instrumentation library, package, or fully qualified class name. Must not be null.

Returns:Meter

a Meter instance.

Since
1.10.0
getMeterProviderback to summary
public static MeterProvider getMeterProvider()

Returns the globally registered MeterProvider.

Since
1.10.0
getPropagatorsback to summary
public static ContextPropagators getPropagators()

Returns the globally registered ContextPropagators for remote propagation of a context.

getTracerback to summary
public static Tracer getTracer(String instrumentationScopeName)

Gets or creates a named tracer instance from the globally registered TracerProvider.

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

Parameters
instrumentationScopeName:String

A name uniquely identifying the instrumentation scope, such as the instrumentation library, package, or fully qualified class name. Must not be null.

Returns:Tracer

a tracer instance.

getTracerback to summary
public static Tracer getTracer(String instrumentationScopeName, String instrumentationScopeVersion)

Gets or creates a named and versioned tracer instance from the globally registered TracerProvider.

This is a shortcut method for getTracerProvider().get(instrumentationScopeName, instrumentationScopeVersion)

Parameters
instrumentationScopeName:String

A name uniquely identifying the instrumentation scope, such as the instrumentation library, package, or fully qualified class name. Must not be null.

instrumentationScopeVersion:String

The version of the instrumentation scope (e.g., "1.0.0").

Returns:Tracer

a tracer instance.

getTracerProviderback to summary
public static TracerProvider getTracerProvider()

Returns the globally registered TracerProvider.

maybeAutoConfigureAndSetGlobalback to summary
private static OpenTelemetry maybeAutoConfigureAndSetGlobal()
Annotations
@Nullable
meterBuilderback to summary
public static MeterBuilder meterBuilder(String instrumentationScopeName)

Creates a MeterBuilder for a named Meter instance.

This is a shortcut method for get().meterBuilder(instrumentationScopeName)

Parameters
instrumentationScopeName:String

A name uniquely identifying the instrumentation scope, such as the instrumentation library, package, or fully qualified class name. Must not be null.

Returns:MeterBuilder

a MeterBuilder instance.

Since
1.10.0
resetForTestback to summary
public static void resetForTest()

Unsets the global OpenTelemetry. This is only meant to be used from tests which need to reconfigure OpenTelemetry.

setback to summary
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. It should only be called once - an attempt to call it a second time will result in an error. If trying to set the global OpenTelemetry multiple times in tests, use GlobalOpenTelemetry#resetForTest() between them.

If you are using the OpenTelemetry SDK, you should generally use OpenTelemetrySdk.builder().buildAndRegisterGlobal() instead of calling this method directly.

tracerBuilderback to summary
public static TracerBuilder tracerBuilder(String instrumentationScopeName)

Creates a TracerBuilder for a named Tracer instance.

This is a shortcut method for get().tracerBuilder(instrumentationScopeName)

Parameters
instrumentationScopeName:String

A name uniquely identifying the instrumentation scope, such as the instrumentation library, package, or fully qualified class name. Must not be null.

Returns:TracerBuilder

a TracerBuilder instance.

Since
1.4.0
io.opentelemetry.api back to summary

pack-priv Class GlobalOpenTelemetry.ObfuscatedOpenTelemetry

extends Object
implements OpenTelemetry
Class Inheritance
  • java.lang.Object
  • io.opentelemetry.api.GlobalOpenTelemetry.ObfuscatedOpenTelemetry
All Implemented Interfaces
io.opentelemetry.api.OpenTelemetry
Annotations
@ThreadSafe

Static global instances are obfuscated when they are returned from the API to prevent users from casting them to their SDK-specific implementation. For example, we do not want users to use patterns like (OpenTelemetrySdk) GlobalOpenTelemetry.get().

Field Summary

Modifier and TypeField and Description
private final OpenTelemetry

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public LoggerProvider
getLogsBridge()

Overrides default io.opentelemetry.api.OpenTelemetry.getLogsBridge.

Returns the LoggerProvider for bridging logs into OpenTelemetry.

public MeterProvider
public ContextPropagators
public TracerProvider
public TracerBuilder
tracerBuilder(String
A name uniquely identifying the instrumentation scope, such as the instrumentation library, package, or fully qualified class name. Must not be null.
instrumentationScopeName
)

Overrides default io.opentelemetry.api.OpenTelemetry.tracerBuilder.

Creates a TracerBuilder for a named Tracer instance.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

delegateback to summary
private final OpenTelemetry delegate

Constructor Detail

ObfuscatedOpenTelemetryback to summary
pack-priv ObfuscatedOpenTelemetry(OpenTelemetry delegate)

Method Detail

getLogsBridgeback to summary
public LoggerProvider getLogsBridge()

Overrides default io.opentelemetry.api.OpenTelemetry.getLogsBridge.

Doc from io.opentelemetry.api.OpenTelemetry.getLogsBridge.

Returns the LoggerProvider for bridging logs into OpenTelemetry.

The OpenTelemetry logs bridge API exists to enable bridging logs from other log frameworks (e.g. SLF4J, Log4j, JUL, Logback, etc) into OpenTelemetry and is NOT a replacement log API.

Annotations
@Override
getMeterProviderback to summary
public MeterProvider getMeterProvider()

Overrides default io.opentelemetry.api.OpenTelemetry.getMeterProvider.

Doc from io.opentelemetry.api.OpenTelemetry.getMeterProvider.

Returns the MeterProvider for this OpenTelemetry.

Annotations
@Override
getPropagatorsback to summary
public ContextPropagators getPropagators()

Implements io.opentelemetry.api.OpenTelemetry.getPropagators.

Doc from io.opentelemetry.api.OpenTelemetry.getPropagators.

Returns the ContextPropagators for this OpenTelemetry.

Annotations
@Override
getTracerProviderback to summary
public TracerProvider getTracerProvider()

Implements io.opentelemetry.api.OpenTelemetry.getTracerProvider.

Doc from io.opentelemetry.api.OpenTelemetry.getTracerProvider.

Returns the TracerProvider for this OpenTelemetry.

Annotations
@Override
tracerBuilderback to summary
public TracerBuilder tracerBuilder(String instrumentationScopeName)

Overrides default io.opentelemetry.api.OpenTelemetry.tracerBuilder.

Doc from io.opentelemetry.api.OpenTelemetry.tracerBuilder.

Creates a TracerBuilder for a named Tracer instance.

Parameters
instrumentationScopeName:String

A name uniquely identifying the instrumentation scope, such as the instrumentation library, package, or fully qualified class name. Must not be null.

Returns:TracerBuilder

a TracerBuilder instance.

Annotations
@Override