lib/ddtrace/tracer.rb in ddtrace-0.18.3 vs lib/ddtrace/tracer.rb in ddtrace-0.19.0

- old
+ new

@@ -8,10 +8,11 @@ require 'ddtrace/context_flush' require 'ddtrace/provider' require 'ddtrace/logger' require 'ddtrace/writer' require 'ddtrace/sampler' +require 'ddtrace/correlation' # \Datadog global namespace that includes all tracing functionality for Tracer and Span classes. module Datadog # A \Tracer keeps track of the time spent by an application processing a single operation. For # example, a trace can be used to track the entire time spent processing a complicated web request. @@ -124,21 +125,27 @@ hostname = options.fetch(:hostname, nil) port = options.fetch(:port, nil) # Those are rare "power-user" options. sampler = options.fetch(:sampler, nil) - priority_sampling = options[:priority_sampling] + priority_sampling = options.fetch(:priority_sampling, nil) max_spans_before_partial_flush = options.fetch(:max_spans_before_partial_flush, nil) min_spans_before_partial_flush = options.fetch(:min_spans_before_partial_flush, nil) partial_flush_timeout = options.fetch(:partial_flush_timeout, nil) @enabled = enabled unless enabled.nil? @sampler = sampler unless sampler.nil? - if priority_sampling + # 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. + if priority_sampling != false && !@sampler.is_a?(PrioritySampler) @sampler = PrioritySampler.new(base_sampler: @sampler) @writer = Writer.new(priority_sampler: @sampler) + elsif priority_sampling == false + @sampler = sampler || Datadog::AllSampler.new if @sampler.is_a?(PrioritySampler) + @writer = Writer.new end @writer.transport.hostname = hostname unless hostname.nil? @writer.transport.port = port unless port.nil? @@ -347,9 +354,14 @@ end # Return the current active root span or +nil+. def active_root_span call_context.current_root_span + end + + # Return a CorrelationIdentifier for active span + def active_correlation + Datadog::Correlation.identifier_from_context(call_context) end # Send the trace to the writer to enqueue the spans list in the agent # sending queue. def write(trace)