module Datadog::Contrib::Resque::ResqueJob

Uses Resque job hooks to create traces

Public Instance Methods

after_perform_shutdown_tracer(*_) click to toggle source
# File lib/ddtrace/contrib/resque/resque_job.rb, line 30
def after_perform_shutdown_tracer(*_)
  shutdown_tracer_when_forked!
end
around_perform(*args) { || ... } click to toggle source
# 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(*_) click to toggle source
# File lib/ddtrace/contrib/resque/resque_job.rb, line 34
def on_failure_shutdown_tracer(*_)
  shutdown_tracer_when_forked!
end
shutdown_tracer_when_forked!() click to toggle source
# File lib/ddtrace/contrib/resque/resque_job.rb, line 38
def shutdown_tracer_when_forked!
  tracer.shutdown! if forked?
end

Private Instance Methods

datadog_configuration() click to toggle source
# File lib/ddtrace/contrib/resque/resque_job.rb, line 58
def datadog_configuration
  Datadog.configuration[:resque]
end
forked?() click to toggle source
# File lib/ddtrace/contrib/resque/resque_job.rb, line 44
def forked?
  pin = Datadog::Pin.get_from(::Resque)
  return false unless pin
  pin.config[:forked] == true
end
span_options() click to toggle source
# File lib/ddtrace/contrib/resque/resque_job.rb, line 50
def span_options
  { service: datadog_configuration[:service_name] }
end
tracer() click to toggle source
# File lib/ddtrace/contrib/resque/resque_job.rb, line 54
def tracer
  datadog_configuration.tracer
end