73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/new_relic/agent/instrumentation/bunny/instrumentation.rb', line 73
def pop_with_tracing
NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)
bunny_error, delivery_info, message_properties, _payload = nil, nil, nil, nil
begin
t0 = Process.clock_gettime(Process::CLOCK_REALTIME)
msg = yield
delivery_info, message_properties, _payload = msg
rescue StandardError => error
bunny_error = error
end
begin
exch_name, exch_type = if delivery_info
[exchange_name(delivery_info.exchange),
exchange_type(delivery_info, channel)]
else
[exchange_name(NewRelic::EMPTY_STR),
exchange_type({}, channel)]
end
segment = NewRelic::Agent::Messaging.start_amqp_consume_segment(
library: LIBRARY,
destination_name: exch_name,
delivery_info: (delivery_info || {}),
message_properties: (message_properties || {headers: {}}),
exchange_type: exch_type,
queue_name: name,
start_time: t0
)
if segment
segment.add_agent_attribute('server.address', channel&.connection&.hostname)
segment.add_agent_attribute('server.port', channel&.connection&.port)
segment.add_agent_attribute('messaging.destination.name', name) segment.add_agent_attribute('messaging.destination_publish.name', exch_name)
segment.add_agent_attribute('message.queueName', name)
segment.add_agent_attribute('messaging.rabbitmq.destination.routing_key', delivery_info&.routing_key)
end
rescue => e
NewRelic::Agent.logger.error('Error starting message broker segment in Bunny::Queue#pop', e)
else
if bunny_error
segment.notice_error(bunny_error)
raise bunny_error
end
ensure
::NewRelic::Agent::Transaction::Segment.finish(segment)
end
msg
end
|