Class: OpenTracing::Instrumentation::Bunny::ConsumeTracer

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/opentracing/instrumentation/bunny/consume_tracer.rb

Overview

ConsumeTracer extract parent span from message headers and create span around passed block

Usage:

consumer_tracer = \
  OpenTracing::Instrumentation::Bunny::ConsumeTracer.new

consumer_tracer = \
  OpenTracing::Instrumentation::Bunny::ConsumeTracer.new do |config|
    config.tracer = custom_tracer
  end

queue.subscribe(block: true) do |delivery_info, properties, payload|
  consume_tracer.consume(delivery_info, properties) do
  end
end

Instance Method Summary collapse

Constructor Details

#initialize(config: ConsumeTracerConfig.new) {|config| ... } ⇒ ConsumeTracer

Returns a new instance of ConsumeTracer.

Parameters:

Yields:

  • (config)


26
27
28
29
# File 'lib/opentracing/instrumentation/bunny/consume_tracer.rb', line 26

def initialize(config: ConsumeTracerConfig.new)
  yield config if block_given?
  @config = config
end

Instance Method Details

#consume(delivery_info, properties) {|scope| ... } ⇒ OpenTracing::Scope?

Extract tracing parent from headers. Create span with tags. If block passed, then span closed after block exit, otherwise return active scope.

without block, otherwise return block result

Parameters:

  • delivery_info (Bunny::DeliveryInfo)
  • properties (Bunny::MessageProperties)

Yields:

  • if block passed, then it called and after scope closed

Yield Parameters:

  • scope (OpenTracing::Scope)

Returns:

  • (OpenTracing::Scope, nil)

    return active scope if called



41
42
43
44
45
46
47
48
# File 'lib/opentracing/instrumentation/bunny/consume_tracer.rb', line 41

def consume(delivery_info, properties)
  span_scope = safe_start_active_span(delivery_info, properties)
  return span_scope unless block_given?

  handle_error(span_scope) do
    yield span_scope
  end
end