Module: NewRelic::Agent::Instrumentation::Bunny::Exchange

Includes:
NewRelic::Agent::Instrumentation::Bunny
Included in:
Bunny::Prepend::Exchange
Defined in:
lib/new_relic/agent/instrumentation/bunny/instrumentation.rb

Constant Summary

Constants included from NewRelic::Agent::Instrumentation::Bunny

DEFAULT_NAME, DEFAULT_TYPE, INSTRUMENTATION_NAME, LIBRARY, SLASH

Instance Method Summary collapse

Methods included from NewRelic::Agent::Instrumentation::Bunny

exchange_name, exchange_type

Instance Method Details

#publish_with_tracing(payload, opts = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/new_relic/agent/instrumentation/bunny/instrumentation.rb', line 31

def publish_with_tracing(payload, opts = {})
  NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)

  begin
    destination = exchange_name(name)

    tracing_enabled =
      NewRelic::Agent::CrossAppTracing.cross_app_enabled? ||
      NewRelic::Agent.config[:'distributed_tracing.enabled']
    opts[:headers] ||= {} if tracing_enabled

    segment = NewRelic::Agent::Messaging.start_amqp_publish_segment(
      library: LIBRARY,
      destination_name: destination,
      headers: opts[:headers],
      routing_key: opts[:routing_key] || opts[:key],
      reply_to: opts[:reply_to],
      correlation_id: opts[:correlation_id],
      exchange_type: type
    )
  rescue => e
    NewRelic::Agent.logger.error('Error starting message broker segment in Bunny::Exchange#publish', e)
    yield
  else
    NewRelic::Agent::Tracer.capture_segment_error(segment) do
      yield
    end
  ensure
    ::NewRelic::Agent::Transaction::Segment.finish(segment)
  end
end