Skip to content

Commit

Permalink
Added: event_sample_rate tag to Sidekiq integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
delner committed Jan 2, 2019
1 parent 0bea126 commit c3c7fa6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
16 changes: 11 additions & 5 deletions lib/ddtrace/contrib/sidekiq/client_tracer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'ddtrace/contrib/sidekiq/tracing'
require 'ddtrace/contrib/sampling'

module Datadog
module Contrib
Expand All @@ -9,26 +10,31 @@ 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']

yield
end
end

private

def configuration
Datadog.configuration[:sidekiq]
end
end
end
end
Expand Down
8 changes: 7 additions & 1 deletion lib/ddtrace/contrib/sidekiq/server_tracer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'ddtrace/contrib/sidekiq/tracing'
require 'ddtrace/contrib/sampling'

module Datadog
module Contrib
Expand All @@ -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)
Expand All @@ -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'])
Expand All @@ -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
Expand Down

0 comments on commit c3c7fa6

Please sign in to comment.