Class: OpenTracing::Instrumentation::Bunny::PublishTracer

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

Overview

PublishTracer trace publishing and inject trace headers into AMQP message

Usage:

exchange = channel.topic(BUNNY_EXCHANGE_NAME)
default_publisher \
  = OpenTracing::Instrumentation::Bunny::PublishTracer.new(exchange)
configured_publisher = \
  OpenTracing::Instrumentation::Bunny::PublishTracer.new(exchange) do |c|
    c.tracer = custom_tracer
  end
publisher.publish(
  '{"message": 123}',
  routing_key: 'key',
)

Instance Method Summary collapse

Constructor Details

#initialize(exchange, config: PublishTracerConfig.new) {|config| ... } ⇒ PublishTracer

Returns a new instance of PublishTracer.

Parameters:

  • exchange (Bunny::Exchange)

Yields:

  • (config)


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

def initialize(exchange, config: PublishTracerConfig.new)
  @exchange = exchange
  yield config if block_given?
  @config = config.dup
end

Instance Method Details

#publish(payload, active_span: tracer.active_span, **opts) ⇒ Bunny::Exchange

Publish message via call ‘exchange.publish`, with injecting tracing into headers and create span around publising call.

For deatils see: www.rubydoc.info/gems/bunny/Bunny/Exchange#publish-instance_method

Parameters:

  • active (OpenTracing::Span)

    allow overide span

Returns:

  • (Bunny::Exchange)


39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/opentracing/instrumentation/bunny/publish_tracer.rb', line 39

def publish(
  payload,
  active_span: tracer.active_span,
  **opts
)
  trace_publish(span: active_span, **opts) do |scope|
    publish_with_headers(
      payload,
      span: scope&.span || active_span,
      **opts,
    )
  end
end