diff --git a/lib/ddtrace/contrib/sidekiq/client_tracer.rb b/lib/ddtrace/contrib/sidekiq/client_tracer.rb index 0c6954abeda..0c9535ac6b4 100644 --- a/lib/ddtrace/contrib/sidekiq/client_tracer.rb +++ b/lib/ddtrace/contrib/sidekiq/client_tracer.rb @@ -1,4 +1,5 @@ require 'ddtrace/contrib/sidekiq/tracing' +require 'ddtrace/contrib/sampling' module Datadog module Contrib @@ -9,19 +10,18 @@ class ClientTracer def initialize(options = {}) super - @sidekiq_service = options[:client_service_name] || Datadog.configuration[:sidekiq][:client_service_name] + @sidekiq_service = options[:client_service_name] || configuration[:client_service_name] + set_service_info(@sidekiq_service) end # Client middleware arguments are documented here: # https://github.com/mperham/sidekiq/wiki/Middleware#client-middleware def call(worker_class, job, queue, redis_pool) - service = @sidekiq_service - set_service_info(service) - resource = job_resource(job) - @tracer.trace(Ext::SPAN_PUSH, service: service) do |span| + @tracer.trace(Ext::SPAN_PUSH, service: @sidekiq_service) do |span| span.resource = resource + Contrib::Sampling.set_event_sample_rate(span, configuration[:event_sample_rate]) span.set_tag(Ext::TAG_JOB_ID, job['jid']) span.set_tag(Ext::TAG_JOB_QUEUE, job['queue']) span.set_tag(Ext::TAG_JOB_WRAPPER, job['class']) if job['wrapped'] @@ -29,6 +29,12 @@ def call(worker_class, job, queue, redis_pool) yield end end + + private + + def configuration + Datadog.configuration[:sidekiq] + end end end end diff --git a/lib/ddtrace/contrib/sidekiq/server_tracer.rb b/lib/ddtrace/contrib/sidekiq/server_tracer.rb index f85108c6f22..cfb200e0b29 100644 --- a/lib/ddtrace/contrib/sidekiq/server_tracer.rb +++ b/lib/ddtrace/contrib/sidekiq/server_tracer.rb @@ -1,4 +1,5 @@ require 'ddtrace/contrib/sidekiq/tracing' +require 'ddtrace/contrib/sampling' module Datadog module Contrib @@ -9,7 +10,7 @@ class ServerTracer def initialize(options = {}) super - @sidekiq_service = options[:service_name] || Datadog.configuration[:sidekiq][:service_name] + @sidekiq_service = options[:service_name] || configuration[:service_name] end def call(worker, job, queue) @@ -20,6 +21,7 @@ def call(worker, job, queue) @tracer.trace(Ext::SPAN_JOB, service: service, span_type: Datadog::Ext::AppTypes::WORKER) do |span| span.resource = resource + Contrib::Sampling.set_event_sample_rate(span, configuration[:event_sample_rate]) span.set_tag(Ext::TAG_JOB_ID, job['jid']) span.set_tag(Ext::TAG_JOB_RETRY, job['retry']) span.set_tag(Ext::TAG_JOB_QUEUE, job['queue']) @@ -32,6 +34,10 @@ def call(worker, job, queue) private + def configuration + Datadog.configuration[:sidekiq] + end + def service_from_worker_config(resource) # Try to get the Ruby class from the resource name. worker_klass = begin