Interface OpenTelemetry
-
- All Known Implementing Classes:
DefaultOpenTelemetry
public interface OpenTelemetryThe entrypoint to telemetry functionality for tracing, metrics and baggage.A 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 Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description static OpenTelemetryBuilder<?>builder()Returns a newOpenTelemetryBuilder.static OpenTelemetryget()Returns the registered globalOpenTelemetry.static MetergetGlobalMeter(java.lang.String instrumentationName)Gets or creates a named meter instance from the globally registeredMeterProvider.static MetergetGlobalMeter(java.lang.String instrumentationName, java.lang.String instrumentationVersion)Gets or creates a named and versioned meter instance from the globally registeredMeterProvider.static MeterProvidergetGlobalMeterProvider()Returns the globally registeredMeterProvider.static io.opentelemetry.context.propagation.ContextPropagatorsgetGlobalPropagators()Returns the globally registeredContextPropagatorsfor remote propagation of a context.static TracergetGlobalTracer(java.lang.String instrumentationName)Gets or creates a named tracer instance from the globally registeredTracerProvider.static TracergetGlobalTracer(java.lang.String instrumentationName, java.lang.String instrumentationVersion)Gets or creates a named and versioned tracer instance from the globally registeredTracerProvider.static TracerProvidergetGlobalTracerProvider()Returns the globally registeredTracerProvider.default MetergetMeter(java.lang.String instrumentationName)Gets or creates a named meter instance from theMeterProviderin thisOpenTelemetry.default MetergetMeter(java.lang.String instrumentationName, java.lang.String instrumentationVersion)Gets or creates a named and versioned meter instance from theMeterProviderin thisOpenTelemetry.MeterProvidergetMeterProvider()Returns theMeterProviderfor thisOpenTelemetry.io.opentelemetry.context.propagation.ContextPropagatorsgetPropagators()Returns theContextPropagatorsfor thisOpenTelemetry.default TracergetTracer(java.lang.String instrumentationName)Gets or creates a named tracer instance from theTracerProviderfor thisOpenTelemetry.default TracergetTracer(java.lang.String instrumentationName, java.lang.String instrumentationVersion)Gets or creates a named and versioned tracer instance from theTracerProviderin thisOpenTelemetry.TracerProvidergetTracerProvider()Returns theTracerProviderfor thisOpenTelemetry.static voidset(OpenTelemetry openTelemetry)Sets theOpenTelemetrythat should be the global instance.static voidsetGlobalPropagators(io.opentelemetry.context.propagation.ContextPropagators propagators)Sets the globally registeredContextPropagatorsfor remote propagation of a context.voidsetPropagators(io.opentelemetry.context.propagation.ContextPropagators propagators)Sets the propagators that this instance should contain.OpenTelemetryBuilder<?>toBuilder()Deprecated.This method should not be used, as it allows unexpected sharing of state across instances.
-
-
-
Method Detail
-
get
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:
java.lang.IllegalStateException- if a provider has been specified by system property using the interface FQCN but the specified provider cannot be found.
-
set
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.
-
getGlobalTracerProvider
static TracerProvider getGlobalTracerProvider()
Returns the globally registeredTracerProvider.
-
getGlobalTracer
static Tracer getGlobalTracer(java.lang.String instrumentationName)
Gets or creates a named tracer instance from the globally registeredTracerProvider.This is a shortcut method for
getGlobalTracerProvider().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.
-
getGlobalTracer
static Tracer getGlobalTracer(java.lang.String instrumentationName, java.lang.String instrumentationVersion)
Gets or creates a named and versioned tracer instance from the globally registeredTracerProvider.This is a shortcut method for
getGlobalTracerProvider().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.
-
getGlobalMeterProvider
static MeterProvider getGlobalMeterProvider()
Returns the globally registeredMeterProvider.
-
getGlobalMeter
static Meter getGlobalMeter(java.lang.String instrumentationName)
Gets or creates a named meter instance from the globally registeredMeterProvider.This is a shortcut method for
getGlobalMeterProvider().get(instrumentationName)- Parameters:
instrumentationName- The name of the instrumentation library, not the name of the instrument*ed* library.- Returns:
- a tracer instance.
-
getGlobalMeter
static Meter getGlobalMeter(java.lang.String instrumentationName, java.lang.String instrumentationVersion)
Gets or creates a named and versioned meter instance from the globally registeredMeterProvider.This is a shortcut method for
getGlobalMeterProvider().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.
-
getGlobalPropagators
static io.opentelemetry.context.propagation.ContextPropagators getGlobalPropagators()
Returns the globally registeredContextPropagatorsfor remote propagation of a context.
-
setGlobalPropagators
static void setGlobalPropagators(io.opentelemetry.context.propagation.ContextPropagators propagators)
Sets the globally registeredContextPropagatorsfor remote propagation of a context.
-
setPropagators
void setPropagators(io.opentelemetry.context.propagation.ContextPropagators propagators)
Sets the propagators that this instance should contain.
-
getTracerProvider
TracerProvider getTracerProvider()
Returns theTracerProviderfor thisOpenTelemetry.
-
getTracer
default Tracer getTracer(java.lang.String instrumentationName)
Gets or creates a named tracer instance from theTracerProviderfor thisOpenTelemetry.- 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
default Tracer getTracer(java.lang.String instrumentationName, java.lang.String instrumentationVersion)
Gets or creates a named and versioned tracer instance from theTracerProviderin thisOpenTelemetry.- 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
MeterProvider getMeterProvider()
Returns theMeterProviderfor thisOpenTelemetry.
-
getMeter
default Meter getMeter(java.lang.String instrumentationName)
Gets or creates a named meter instance from theMeterProviderin thisOpenTelemetry.- Parameters:
instrumentationName- The name of the instrumentation library, not the name of the instrument*ed* library.- Returns:
- a tracer instance.
-
getMeter
default Meter getMeter(java.lang.String instrumentationName, java.lang.String instrumentationVersion)
Gets or creates a named and versioned meter instance from theMeterProviderin thisOpenTelemetry.- 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
io.opentelemetry.context.propagation.ContextPropagators getPropagators()
Returns theContextPropagatorsfor thisOpenTelemetry.
-
toBuilder
@Deprecated OpenTelemetryBuilder<?> toBuilder()
Deprecated.This method should not be used, as it allows unexpected sharing of state across instances. It will be removed in the next release.Returns a newOpenTelemetryBuilderwith the configuration of thisOpenTelemetry.
-
builder
static OpenTelemetryBuilder<?> builder()
Returns a newOpenTelemetryBuilder.
-
-