Class: Datadog::Tracing::Contrib::DelayedJob::Plugin
- Inherits:
-
Delayed::Plugin
- Object
- Delayed::Plugin
- Datadog::Tracing::Contrib::DelayedJob::Plugin
- Defined in:
- lib/datadog/tracing/contrib/delayed_job/plugin.rb
Overview
DelayedJob plugin that instruments invoke_job hook
Class Method Summary collapse
- .configuration ⇒ Object
- .flush(worker) {|worker| ... } ⇒ Object
- .instrument_enqueue(job, &block) ⇒ Object
- .instrument_invoke(job, &block) ⇒ Object
- .job_name(job) ⇒ Object
- .set_sample_rate(span) ⇒ Object
Class Method Details
.configuration ⇒ Object
82 83 84 |
# File 'lib/datadog/tracing/contrib/delayed_job/plugin.rb', line 82 def self.configuration Datadog.configuration.tracing[:delayed_job] end |
.flush(worker) {|worker| ... } ⇒ Object
76 77 78 79 80 |
# File 'lib/datadog/tracing/contrib/delayed_job/plugin.rb', line 76 def self.flush(worker, &block) yield worker Tracing.shutdown! if Tracing.enabled? end |
.instrument_enqueue(job, &block) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/datadog/tracing/contrib/delayed_job/plugin.rb', line 47 def self.instrument_enqueue(job, &block) return yield(job) unless Tracing.enabled? Tracing.trace( Ext::SPAN_ENQUEUE, service: configuration[:client_service_name], resource: job_name(job) ) do |span| span.set_tag(Tracing::Metadata::Ext::TAG_SVC_SRC, Ext::TAG_COMPONENT) set_sample_rate(span) # Measure service stats Contrib::Analytics.set_measured(span) span.set_tag(Ext::TAG_QUEUE, job.queue) if job.queue span.set_tag(Ext::TAG_PRIORITY, job.priority) span.type = Tracing::Metadata::Ext::AppTypes::TYPE_WORKER span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT) span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_ENQUEUE) span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_PRODUCER) span.set_tag(Contrib::Ext::Messaging::TAG_SYSTEM, Ext::TAG_COMPONENT) yield job end end |
.instrument_invoke(job, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/datadog/tracing/contrib/delayed_job/plugin.rb', line 15 def self.instrument_invoke(job, &block) return yield(job) unless Tracing.enabled? Tracing.trace( Ext::SPAN_JOB, service: configuration[:service_name], resource: job_name(job), on_error: configuration[:on_error] ) do |span| span.set_tag(Tracing::Metadata::Ext::TAG_SVC_SRC, Ext::TAG_COMPONENT) set_sample_rate(span) # Measure service stats Contrib::Analytics.set_measured(span) 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.type = Tracing::Metadata::Ext::AppTypes::TYPE_WORKER span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT) span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_JOB) span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CONSUMER) span.set_tag(Contrib::Ext::Messaging::TAG_SYSTEM, Ext::TAG_COMPONENT) yield job end end |
.job_name(job) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/datadog/tracing/contrib/delayed_job/plugin.rb', line 86 def self.job_name(job) # When DelayedJob is used through ActiveJob, we need to parse the payload differentely # to get the actual job name return job.payload_object.job_data["job_class"] if job.payload_object.respond_to?(:job_data) job.name end |
.set_sample_rate(span) ⇒ Object
94 95 96 97 98 99 |
# File 'lib/datadog/tracing/contrib/delayed_job/plugin.rb', line 94 def self.set_sample_rate(span) # Set analytics sample rate if Contrib::Analytics.enabled?(configuration[:analytics_enabled]) Contrib::Analytics.set_sample_rate(span, configuration[:analytics_sample_rate]) end end |