class Datadog::Contrib::DelayedJob::Plugin

DelayedJob plugin that instruments invoke_job hook

Public Class Methods

configuration() click to toggle source
# File lib/ddtrace/contrib/delayed_job/plugin.rb, line 54
def self.configuration
  Datadog.configuration[:delayed_job]
end
flush(worker) { |worker| ... } click to toggle source
# File lib/ddtrace/contrib/delayed_job/plugin.rb, line 48
def self.flush(worker, &block)
  yield worker

  tracer.shutdown! if tracer && tracer.enabled
end
instrument_enqueue(job) { |job| ... } click to toggle source
# File lib/ddtrace/contrib/delayed_job/plugin.rb, line 31
def self.instrument_enqueue(job, &block)
  return block.call(job) unless tracer && tracer.enabled

  tracer.trace(Ext::SPAN_ENQUEUE, service: configuration[:client_service_name], resource: job_name(job)) do |span|
    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.span_type = Datadog::Ext::AppTypes::WORKER

    yield job
  end
end
instrument_invoke(job) { |job| ... } click to toggle source
# File lib/ddtrace/contrib/delayed_job/plugin.rb, line 11
def self.instrument_invoke(job, &block)
  return block.call(job) unless tracer && tracer.enabled

  tracer.trace(Ext::SPAN_JOB, service: configuration[:service_name], resource: job_name(job),
                              on_error: configuration[:error_handler]) do |span|
    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.span_type = Datadog::Ext::AppTypes::WORKER

    yield job
  end
end
job_name(job) click to toggle source
# File lib/ddtrace/contrib/delayed_job/plugin.rb, line 62
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) click to toggle source
# File lib/ddtrace/contrib/delayed_job/plugin.rb, line 70
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
tracer() click to toggle source
# File lib/ddtrace/contrib/delayed_job/plugin.rb, line 58
def self.tracer
  configuration[:tracer]
end