Class: Datadog::Contrib::Shoryuken::Tracer

Inherits:
Object
  • Object
show all
Defined in:
lib/ddtrace/contrib/shoryuken/tracer.rb

Overview

Tracer is a Shoryuken server-side middleware which traces executed jobs

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Tracer

Returns a new instance of Tracer.



9
10
11
12
13
# File 'lib/ddtrace/contrib/shoryuken/tracer.rb', line 9

def initialize(options = {})
  @tracer = options[:tracer] || configuration[:tracer]
  @shoryuken_service = options[:service_name] || configuration[:service_name]
  @error_handler = options[:error_handler] || configuration[:error_handler]
end

Instance Method Details

#call(worker_instance, queue, sqs_msg, body) ⇒ 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
# File 'lib/ddtrace/contrib/shoryuken/tracer.rb', line 15

def call(worker_instance, queue, sqs_msg, body)
  @tracer.trace(
    Ext::SPAN_JOB,
    service: @shoryuken_service,
    span_type: Datadog::Ext::AppTypes::WORKER,
    on_error: @error_handler
  ) do |span|
    # Set analytics sample rate
    if Contrib::Analytics.enabled?(configuration[:analytics_enabled])
      Contrib::Analytics.set_sample_rate(span, configuration[:analytics_sample_rate])
    end

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

    span.resource = resource(worker_instance, body)
    span.set_tag(Ext::TAG_JOB_ID, sqs_msg.message_id)
    span.set_tag(Ext::TAG_JOB_QUEUE, queue)
    span.set_tag(Ext::TAG_JOB_ATTRIBUTES, sqs_msg.attributes) if sqs_msg.respond_to?(:attributes)
    span.set_tag(Ext::TAG_JOB_BODY, body) if configuration[:tag_body]

    yield
  end
end