lib/opentelemetry.rb in opentelemetry-api-0.16.0 vs lib/opentelemetry.rb in opentelemetry-api-0.17.0
- old
+ new
@@ -7,26 +7,27 @@
require 'logger'
require 'opentelemetry/error'
require 'opentelemetry/context'
require 'opentelemetry/baggage'
-require_relative './opentelemetry/instrumentation'
-require 'opentelemetry/metrics'
require 'opentelemetry/trace'
+require 'opentelemetry/internal'
require 'opentelemetry/version'
# OpenTelemetry is an open source observability framework, providing a
# general-purpose API, SDK, and related tools required for the instrumentation
# of cloud-native software, frameworks, and libraries.
#
# The OpenTelemetry module provides global accessors for telemetry objects.
module OpenTelemetry
extend self
- attr_writer :tracer_provider, :meter_provider, :propagation, :baggage,
- :logger, :error_handler
+ @mutex = Mutex.new
+ @tracer_provider = Internal::ProxyTracerProvider.new
+ attr_writer :propagation, :baggage, :logger, :error_handler
+
# @return [Object, Logger] configured Logger or a default STDOUT Logger.
def logger
@logger ||= Logger.new(STDOUT, level: ENV['OTEL_LOG_LEVEL'] || Logger::INFO)
end
@@ -42,38 +43,37 @@
# @param [optional String] message An error message.
def handle_error(exception: nil, message: nil)
error_handler.call(exception: exception, message: message)
end
+ # Register the global tracer provider.
+ #
+ # @param [TracerProvider] provider A tracer provider to register as the
+ # global instance.
+ def tracer_provider=(provider)
+ @mutex.synchronize do
+ if @tracer_provider.instance_of? Internal::ProxyTracerProvider
+ logger.debug("Upgrading default proxy tracer provider to #{provider.class}")
+ @tracer_provider.delegate = provider
+ end
+ @tracer_provider = provider
+ end
+ end
+
# @return [Object, Trace::TracerProvider] registered tracer provider or a
# default no-op implementation of the tracer provider.
def tracer_provider
- @tracer_provider ||= Trace::TracerProvider.new
+ @mutex.synchronize { @tracer_provider }
end
- # @return [Object, Metrics::MeterProvider] registered meter provider or a
- # default no-op implementation of the meter provider.
- def meter_provider
- @meter_provider ||= Metrics::MeterProvider.new
- end
-
- # @return [Instrumentation::Registry] registry containing all known
- # instrumentation
- def instrumentation_registry
- @instrumentation_registry ||= Instrumentation::Registry.new
- end
-
- # @return [Object, Baggage::Manager] registered
+ # @return [Object, Baggage::NoopManager] registered
# baggage manager or a default no-op implementation of the
# manager.
def baggage
- @baggage ||= Baggage::Manager.new
+ @baggage ||= Baggage::NoopManager.new
end
# @return [Context::Propagation::Propagator] a propagator instance
def propagation
- @propagation ||= Context::Propagation::Propagator.new(
- Context::Propagation::NoopInjector.new,
- Context::Propagation::NoopExtractor.new
- )
+ @propagation ||= Context::Propagation::NoopTextMapPropagator.new
end
end