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

Defined in:
lib/datadog/tracing/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



60
61
62
# File 'lib/datadog/tracing/contrib/resque/resque_job.rb', line 60

def after_perform_shutdown_tracer(*_)
  shutdown_tracer_when_forked!
end

#around_perform0_datadog(*args) ⇒ Object

‘around_perform` hooks are executed in alphabetical order. we use the lowest printable character that allows for an inline method definition (’0’), alongside our naming prefix for identification.

We could, in theory, use any character (e.g “x00”), but this will lead to unreadable stack traces that contain this method call.

We could also just use ‘around_perform` but this might override the user’s own method.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/datadog/tracing/contrib/resque/resque_job.rb', line 34

def around_perform0_datadog(*args)
  return yield unless datadog_configuration && Tracing.enabled?

  Tracing.trace(Ext::SPAN_JOB, **span_options) do |span|
    span.resource = args.first.is_a?(Hash) && args.first['job_class'] || name
    span.type = Tracing::Metadata::Ext::AppTypes::TYPE_WORKER

    span.set_tag(Contrib::Ext::Messaging::TAG_SYSTEM, Ext::TAG_COMPONENT)

    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)

    # 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



64
65
66
# File 'lib/datadog/tracing/contrib/resque/resque_job.rb', line 64

def on_failure_shutdown_tracer(*_)
  shutdown_tracer_when_forked!
end

#shutdown_tracer_when_forked!Object



68
69
70
# File 'lib/datadog/tracing/contrib/resque/resque_job.rb', line 68

def shutdown_tracer_when_forked!
  Tracing.shutdown! if forked?
end