Class: Istox::Xray::RabbitmqConsumerInterceptor

Inherits:
Object
  • Object
show all
Defined in:
lib/istox/helpers/xray/rabbitmq_consumer_interceptor.rb

Instance Method Summary collapse

Instance Method Details

#call(payload, _metadata, delivery_info) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/istox/helpers/xray/rabbitmq_consumer_interceptor.rb', line 6

def call(payload, , delivery_info)
  payload_hash = payload.to_h

  trace_id = (payload_hash[:xray_trace_id] if payload_hash.key?(:xray_trace_id))
  parent_id = (payload_hash[:xray_parent_id] if payload_hash.key?(:xray_parent_id))
  Thread.current[:tracer_id] = trace_id

  arr = [delivery_info[:exchange]&.downcase, delivery_info[:routing_key]&.downcase, payload_hash[:type]&.downcase].compact

  XRay.recorder.begin_segment("#{::Istox::Xray::XrayInitializer.service_name}.rabbitmq.#{arr.join('.')}",
                              trace_id: trace_id, parent_id: parent_id)

  result = yield # this returns consumer handler message

  XRay.recorder.end_segment

  result
rescue StandardError => e
  log.error e
  raise e
end