lib/opentelemetry/sdk/configurator.rb in opentelemetry-sdk-1.0.0.rc2 vs lib/opentelemetry/sdk/configurator.rb in opentelemetry-sdk-1.0.0.rc3

- old
+ new

@@ -7,10 +7,26 @@ module OpenTelemetry module SDK # The configurator provides defaults and facilitates configuring the # SDK for use. class Configurator # rubocop:disable Metrics/ClassLength + # @api private + class NoopTextMapPropagator + EMPTY_LIST = [].freeze + private_constant(:EMPTY_LIST) + + def inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter); end + + def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter) + context + end + + def fields + EMPTY_LIST + end + end + USE_MODE_UNSPECIFIED = 0 USE_MODE_ONE = 1 USE_MODE_ALL = 2 private_constant :USE_MODE_UNSPECIFIED, :USE_MODE_ONE, :USE_MODE_ALL @@ -58,21 +74,21 @@ # The most recent assigned value will be used in the event of repeated # calls to this setter. # @param [String] service_name The value to be used as the service name def service_name=(service_name) self.resource = OpenTelemetry::SDK::Resources::Resource.create( - OpenTelemetry::SDK::Resources::Constants::SERVICE_RESOURCE[:name] => service_name + OpenTelemetry::SemanticConventions::Resource::SERVICE_NAME => service_name ) end # Accepts a string that is merged in as the service.version resource attribute. # The most recent assigned value will be used in the event of repeated # calls to this setter. # @param [String] service_version The value to be used as the service version def service_version=(service_version) self.resource = OpenTelemetry::SDK::Resources::Resource.create( - OpenTelemetry::SDK::Resources::Constants::SERVICE_RESOURCE[:version] => service_version + OpenTelemetry::SemanticConventions::Resource::SERVICE_VERSION => service_version ) end # Install an instrumentation with specificied optional +config+. # Use can be called multiple times to install multiple instrumentation. @@ -147,25 +163,27 @@ OpenTelemetry::Instrumentation.registry.install_all(@instrumentation_config_map) end end def configure_span_processors - processors = @span_processors.empty? ? [wrapped_exporter_from_env].compact : @span_processors + processors = @span_processors.empty? ? wrapped_exporters_from_env.compact : @span_processors processors.each { |p| tracer_provider.add_span_processor(p) } end - def wrapped_exporter_from_env - exporter = ENV.fetch('OTEL_TRACES_EXPORTER', 'otlp') - case exporter - when 'none' then nil - when 'otlp' then fetch_exporter(exporter, 'OpenTelemetry::Exporter::OTLP::Exporter') - when 'jaeger' then fetch_exporter(exporter, 'OpenTelemetry::Exporter::Jaeger::CollectorExporter') - when 'zipkin' then fetch_exporter(exporter, 'OpenTelemetry::Exporter::Zipkin::Exporter') - when 'console' then Trace::Export::SimpleSpanProcessor.new(Trace::Export::ConsoleSpanExporter.new) - else - OpenTelemetry.logger.warn "The #{exporter} exporter is unknown and cannot be configured, spans will not be exported" - nil + def wrapped_exporters_from_env + exporters = ENV.fetch('OTEL_TRACES_EXPORTER', 'otlp') + exporters.split(',').map do |exporter| + case exporter.strip + when 'none' then nil + when 'otlp' then fetch_exporter(exporter, 'OpenTelemetry::Exporter::OTLP::Exporter') + when 'jaeger' then fetch_exporter(exporter, 'OpenTelemetry::Exporter::Jaeger::CollectorExporter') + when 'zipkin' then fetch_exporter(exporter, 'OpenTelemetry::Exporter::Zipkin::Exporter') + when 'console' then Trace::Export::SimpleSpanProcessor.new(Trace::Export::ConsoleSpanExporter.new) + else + OpenTelemetry.logger.warn "The #{exporter} exporter is unknown and cannot be configured, spans will not be exported" + nil + end end end def configure_propagation # rubocop:disable Metrics/CyclomaticComplexity propagators = ENV.fetch('OTEL_PROPAGATORS', 'tracecontext,baggage').split(',').uniq.collect do |propagator| @@ -177,10 +195,10 @@ when 'jaeger' then fetch_propagator(propagator, 'OpenTelemetry::Propagator::Jaeger') when 'xray' then fetch_propagator(propagator, 'OpenTelemetry::Propagator::XRay') when 'ottrace' then fetch_propagator(propagator, 'OpenTelemetry::Propagator::OTTrace') else OpenTelemetry.logger.warn "The #{propagator} propagator is unknown and cannot be configured" - Context::Propagation::NoopTextMapPropagator.new + NoopTextMapPropagator.new end end OpenTelemetry.propagation = Context::Propagation::CompositeTextMapPropagator.compose_propagators((@propagators || propagators).compact) end