class Datadog::Contrib::Shoryuken::Tracer

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

Public Class Methods

new(options = {}) click to toggle source
# 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

Public Instance Methods

call(worker_instance, queue, sqs_msg, body) { || ... } click to toggle source
# 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

Private Instance Methods

configuration() click to toggle source
# File lib/ddtrace/contrib/shoryuken/tracer.rb, line 50
def configuration
  Datadog.configuration[:shoryuken]
end
resource(worker_instance, body) click to toggle source
# File lib/ddtrace/contrib/shoryuken/tracer.rb, line 42
def resource(worker_instance, body)
  # If it's a Hash, try to get the job class from it.
  # This is for ActiveJob compatibility.
  job_class = body['job_class'] if body.is_a?(Hash)
  # If nothing is available, use the worker class name.
  job_class || worker_instance.class.name
end