Class: Datadog::Contrib::DelayedJob::Plugin
- Inherits:
-
Delayed::Plugin
- Object
- Delayed::Plugin
- Datadog::Contrib::DelayedJob::Plugin
- Defined in:
- lib/ddtrace/contrib/delayed_job/plugin.rb
Overview
DelayedJob plugin that instruments invoke_job hook
Class Method Summary collapse
- .configuration ⇒ Object
- .flush(worker) {|worker| ... } ⇒ Object
- .instrument(job, &block) ⇒ Object
- .tracer ⇒ Object
Class Method Details
.configuration ⇒ Object
42 43 44 |
# File 'lib/ddtrace/contrib/delayed_job/plugin.rb', line 42 def self.configuration Datadog.configuration[:delayed_job] end |
.flush(worker) {|worker| ... } ⇒ Object
36 37 38 39 40 |
# File 'lib/ddtrace/contrib/delayed_job/plugin.rb', line 36 def self.flush(worker, &block) yield worker tracer.shutdown! if tracer && tracer.enabled end |
.instrument(job, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ddtrace/contrib/delayed_job/plugin.rb', line 10 def self.instrument(job, &block) return block.call(job) unless tracer && tracer.enabled # When DelayedJob is used through ActiveJob, we need to parse the payload differentely # to get the actual job name job_name = if job.payload_object.respond_to?(:job_data) job.payload_object.job_data['job_class'] else job.name end tracer.trace(Ext::SPAN_JOB, service: configuration[:service_name], resource: job_name) do |span| # Set analytics sample rate if Contrib::Analytics.enabled?(configuration[:analytics_enabled]) Contrib::Analytics.set_sample_rate(span, configuration[:analytics_sample_rate]) end 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) span.set_tag(Ext::TAG_ATTEMPTS, job.attempts) span.span_type = Datadog::Ext::AppTypes::WORKER yield job end end |
.tracer ⇒ Object
46 47 48 |
# File 'lib/ddtrace/contrib/delayed_job/plugin.rb', line 46 def self.tracer configuration[:tracer] end |