Class: OpenTracing::Instrumentation::Bunny::PublishTracer
- Inherits:
-
Object
- Object
- OpenTracing::Instrumentation::Bunny::PublishTracer
- 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
-
#initialize(exchange, config: PublishTracerConfig.new) {|config| ... } ⇒ PublishTracer
constructor
A new instance of PublishTracer.
-
#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.
Constructor Details
#initialize(exchange, config: PublishTracerConfig.new) {|config| ... } ⇒ PublishTracer
Returns a new instance of PublishTracer.
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
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 |