lib/ddtrace/tracer.rb in ddtrace-0.34.2 vs lib/ddtrace/tracer.rb in ddtrace-0.35.0

- old
+ new

@@ -28,11 +28,11 @@ DEFAULT_ON_ERROR = proc { |span, error| span.set_error(error) unless span.nil? } def services # Only log each deprecation warning once (safeguard against log spam) Datadog::Patcher.do_once('Tracer#set_service_info') do - Datadog::Logger.log.warn('services: Usage of Tracer.services has been deprecated') + Datadog.logger.warn('services: Usage of Tracer.services has been deprecated') end {} end @@ -68,26 +68,27 @@ # time of sections of code. Available +options+ are: # # * +enabled+: set if the tracer submits or not spans to the local agent. It's enabled # by default. def initialize(options = {}) - @enabled = options.fetch(:enabled, true) - @writer = options.fetch(:writer, Datadog::Writer.new) - @sampler = options.fetch(:sampler, Datadog::AllSampler.new) - - @provider = options.fetch(:context_provider, Datadog::DefaultContextProvider.new) - @provider ||= Datadog::DefaultContextProvider.new # @provider should never be nil - + # Configurable options @context_flush = if options[:partial_flush] Datadog::ContextFlush::Partial.new(options) else Datadog::ContextFlush::Finished.new end + @default_service = options[:default_service] + @enabled = options.fetch(:enabled, true) + @provider = options.fetch(:context_provider, Datadog::DefaultContextProvider.new) + @sampler = options.fetch(:sampler, Datadog::AllSampler.new) + @tags = options.fetch(:tags, {}) + @writer = options.fetch(:writer, Datadog::Writer.new) + + # Instance variables @mutex = Mutex.new - @tags = options.fetch(:tags, Datadog.configuration.tags) - @default_service = options.fetch(:default_service, Datadog.configuration.service) + @provider ||= Datadog::DefaultContextProvider.new # @provider should never be nil # Enable priority sampling by default activate_priority_sampling!(@sampler) end @@ -112,26 +113,28 @@ @enabled = enabled unless enabled.nil? @sampler = sampler unless sampler.nil? configure_writer(options) - @context_flush = if options[:partial_flush] - Datadog::ContextFlush::Partial.new(options) - else - Datadog::ContextFlush::Finished.new - end + if options.key?(:partial_flush) + @context_flush = if options[:partial_flush] + Datadog::ContextFlush::Partial.new(options) + else + Datadog::ContextFlush::Finished.new + end + end end # Set the information about the given service. A valid example is: # # tracer.set_service_info('web-application', 'rails', 'web') # # set_service_info is deprecated, no service information needs to be tracked def set_service_info(service, app, app_type) # Only log each deprecation warning once (safeguard against log spam) Datadog::Patcher.do_once('Tracer#set_service_info') do - Datadog::Logger.log.warn(%( + Datadog.logger.warn(%( set_service_info: Usage of set_service_info has been deprecated, service information no longer needs to be reported to the trace agent. )) end end @@ -142,11 +145,11 @@ def default_service return @default_service if instance_variable_defined?(:@default_service) && @default_service begin @default_service = File.basename($PROGRAM_NAME, '.*') rescue StandardError => e - Datadog::Logger.log.error("unable to guess default service: #{e}") + Datadog.logger.error("unable to guess default service: #{e}") @default_service = 'ruby'.freeze end @default_service end @@ -266,11 +269,11 @@ begin begin span = start_span(name, options) # rubocop:disable Lint/UselessAssignment rescue StandardError => e - Datadog::Logger.log.debug('Failed to start span: #{e}') + Datadog.logger.debug('Failed to start span: #{e}') ensure return_value = yield(span) end # rubocop:disable Lint/RescueException # Here we really want to catch *any* exception, not only StandardError, @@ -332,15 +335,15 @@ # Send the trace to the writer to enqueue the spans list in the agent # sending queue. def write(trace) return if @writer.nil? || !@enabled - if Datadog::Logger.debug_logging - Datadog::Logger.log.debug("Writing #{trace.length} spans (enabled: #{@enabled})") + if Datadog.configuration.diagnostics.debug + Datadog.logger.debug("Writing #{trace.length} spans (enabled: #{@enabled})") str = String.new('') PP.pp(trace, str) - Datadog::Logger.log.debug(str) + Datadog.logger.debug(str) end @writer.write(trace) end @@ -353,14 +356,14 @@ hostname = options.fetch(:hostname, nil) port = options.fetch(:port, nil) sampler = options.fetch(:sampler, nil) priority_sampling = options.fetch(:priority_sampling, nil) writer = options.fetch(:writer, nil) - transport_options = options.fetch(:transport_options, {}) + transport_options = options.fetch(:transport_options, {}).dup # Compile writer options - writer_options = options.fetch(:writer_options, {}) + writer_options = options.fetch(:writer_options, {}).dup rebuild_writer = !writer_options.empty? # Re-build the sampler and writer if priority sampling is enabled, # but neither are configured. Verify the sampler isn't already a # priority sampler too, so we don't wrap one with another. @@ -392,17 +395,9 @@ transport_options[:port] = port unless port.nil? rebuild_writer = true end writer_options[:transport_options] = transport_options - - # ensure any configuration to runtime_metrics statsd client is - # passed on when writer gets rebuilt - unless writer_options.key?(:runtime_metrics) - if @writer && !@writer.runtime_metrics.nil? - writer_options[:runtime_metrics] = @writer.runtime_metrics - end - end if rebuild_writer || writer # Make sure old writer is shut down before throwing away. # Don't want additional threads running... @writer.stop unless writer.nil?