Skip to content

Commit

Permalink
Added: event_sample_rate tag to DelayedJob integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
delner committed Dec 28, 2018
1 parent 3f92aa5 commit 1f6651c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/ddtrace/contrib/delayed_job/plugin.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'delayed/plugin'
require 'ddtrace/contrib/sampling'
require 'ddtrace/contrib/delayed_job/ext'

module Datadog
Expand All @@ -18,6 +19,7 @@ def self.instrument(job, &block)
end

tracer.trace(Ext::SPAN_JOB, service: configuration[:service_name], resource: job_name) do |span|
Contrib::Sampling.set_event_sample_rate(span, configuration[:event_sample_rate])
span.set_tag(Ext::TAG_ID, job.id)
span.set_tag(Ext::TAG_QUEUE, job.queue) if job.queue
span.set_tag(Ext::TAG_PRIORITY, job.priority)
Expand Down
23 changes: 21 additions & 2 deletions spec/ddtrace/contrib/delayed_job/plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ def job_data
end

let(:tracer) { get_test_tracer }
let(:options) { { tracer: tracer } }

before do
Datadog.configure { |c| c.use :delayed_job, tracer: tracer }

Datadog.configure { |c| c.use :delayed_job, options }
Delayed::Worker.delay_jobs = false
end

after(:each) { Datadog.registry[:delayed_job].reset_configuration! }

describe 'instrumenting worker execution' do
let(:worker) { double(:worker, name: 'worker') }
before do
Expand Down Expand Up @@ -100,6 +102,23 @@ def job_data
expect(span.get_tag('delayed_job.attempts')).to eq('0')
end

describe 'event sample rate' do
context 'when not configured' do
it 'is not included in the tags' do
expect(span.get_tag(Datadog::Ext::Priority::TAG_EVENT_SAMPLE_RATE)).to be nil
end
end

context 'when set' do
let(:options) { super().merge(event_sample_rate: event_sample_rate) }
let(:event_sample_rate) { 0.5 }

it 'is included in the tags' do
expect(span.get_tag(Datadog::Ext::Priority::TAG_EVENT_SAMPLE_RATE)).to eq(event_sample_rate.to_s)
end
end
end

context 'when queue name is set' do
let(:queue_name) { 'queue_name' }
let(:job_params) { { queue: queue_name } }
Expand Down

0 comments on commit 1f6651c

Please sign in to comment.