class OpenTracing::Instrumentation::Hutch::ConsumeTracer

ConsumeTracer trace Hutch consumer. Cannot be configured, Use ConsumeTracerBuilder for configuration.

Usage:

Hutch::Config.set(
  :tracer,
  OpenTracing::Instrumentation::Hutch::ConsumeTracer,
)

Attributes

consumer[R]

Public Class Methods

new(consumer, config: ConsumeTracerConfig.new) click to toggle source
# File lib/opentracing/instrumentation/hutch/consume_tracer.rb, line 17
def initialize(consumer, config: ConsumeTracerConfig.new)
  @consumer = consumer
  @config = config
end

Public Instance Methods

handle(message) click to toggle source

Method handle called by Hutch on message. This method start active span, process consumer and close span.

# File lib/opentracing/instrumentation/hutch/consume_tracer.rb, line 24
def handle(message)
  scope = safe_start_active_span(message)
  consumer.process(message)
rescue StandardError => e
  error_writer.write_error(scope.span, e) if scope
  raise e
ensure
  # Close scope if exists
  scope&.close
end

Private Instance Methods

build_operation_name(message) click to toggle source
# File lib/opentracing/instrumentation/hutch/consume_tracer.rb, line 67
def build_operation_name(message)
  operation_name_builder.build_operation_name(
    consumer,
    message,
  )
end
build_references(headers) click to toggle source
# File lib/opentracing/instrumentation/hutch/consume_tracer.rb, line 74
def build_references(headers)
  return if headers.nil?

  span_context = tracer.extract(
    OpenTracing::FORMAT_TEXT_MAP,
    headers,
  )
  return if span_context.nil?

  [OpenTracing::Reference.follows_from(span_context)]
end
safe_start_active_span(message) click to toggle source
# File lib/opentracing/instrumentation/hutch/consume_tracer.rb, line 48
def safe_start_active_span(message)
  start_active_span(message)
rescue StandardError => e
  logger.error(e)
  nil
end
start_active_span(message) click to toggle source
# File lib/opentracing/instrumentation/hutch/consume_tracer.rb, line 55
def start_active_span(message)
  operation_name = build_operation_name(message)
  tags = tags_builder.build_tags(consumer, message)
  references = build_references(message.properties[:headers])

  tracer.start_active_span(
    operation_name,
    tags: tags,
    references: references,
  )
end