Module: NewRelic::Agent::Instrumentation::Bunny::Queue

Includes:
NewRelic::Agent::Instrumentation::Bunny
Included in:
Bunny::Prepend::Queue
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

#pop_with_tracingObject



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) # for consume, this is queue 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

#purge_with_tracingObject



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/new_relic/agent/instrumentation/bunny/instrumentation.rb', line 125

def purge_with_tracing
  NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)

  begin
    type = server_named? ? :temporary_queue : :queue
    segment = NewRelic::Agent::Tracer.start_message_broker_segment(
      action: :purge,
      library: LIBRARY,
      destination_type: type,
      destination_name: name
    )
  rescue => e
    NewRelic::Agent.logger.error('Error starting message broker segment in Bunny::Queue#purge', e)
    yield
  else
    NewRelic::Agent::Tracer.capture_segment_error(segment) do
      yield
    end
  ensure
    ::NewRelic::Agent::Transaction::Segment.finish(segment)
  end
end