Module: Datadog::Contrib::Resque::ResqueJob

Defined in:
lib/ddtrace/contrib/resque/resque_job.rb

Overview

Uses Resque job hooks to create traces

Instance Method Summary collapse

Instance Method Details

#after_perform_shutdown_tracer(*_) ⇒ Object



30
31
32
# File 'lib/ddtrace/contrib/resque/resque_job.rb', line 30

def after_perform_shutdown_tracer(*_)
  shutdown_tracer_when_forked!
end

#around_perform(*args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ddtrace/contrib/resque/resque_job.rb', line 12

def around_perform(*args)
  return yield unless datadog_configuration && tracer

  tracer.trace(Ext::SPAN_JOB, span_options) do |span|
    span.resource = args.first.is_a?(Hash) && args.first['job_class'] || name
    span.span_type = Datadog::Ext::AppTypes::WORKER
    # Set analytics sample rate
    if Contrib::Analytics.enabled?(datadog_configuration[:analytics_enabled])
      Contrib::Analytics.set_sample_rate(span, datadog_configuration[:analytics_sample_rate])
    end

    # Measure service stats
    Contrib::Analytics.set_measured(span)

    yield
  end
end

#on_failure_shutdown_tracer(*_) ⇒ Object



34
35
36
# File 'lib/ddtrace/contrib/resque/resque_job.rb', line 34

def on_failure_shutdown_tracer(*_)
  shutdown_tracer_when_forked!
end

#shutdown_tracer_when_forked!Object



38
39
40
# File 'lib/ddtrace/contrib/resque/resque_job.rb', line 38

def shutdown_tracer_when_forked!
  tracer.shutdown! if forked?
end