Class: Istox::Xray::RabbitmqPublisherInterceptor

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

Instance Method Summary collapse

Instance Method Details

#call(message, options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/istox/helpers/xray/rabbitmq_publisher_interceptor.rb', line 6

def call(message, options)
  no_segment = false

  begin
    no_segment = XRay.recorder.current_segment.blank?
  rescue XRay::ContextMissingError
    no_segment = true
  end

  ## usually we have active segment for client interceptor
  ## but in some special case we might not have segment initiated
  ## eg. when running from rails console,
  ## in those case we will initiate the segment here manully
  XRay.recorder.begin_segment('rabbitmq_publish') if no_segment

  XRay.recorder.begin_subsegment("rabbitmq_publish.#{options[:routing_key]}")

  message[:xray_trace_id] = XRay.recorder.current_segment.trace_id
  message[:xray_parent_id] = XRay.recorder.current_segment.id
  Thread.current[:tracer_id] = XRay.recorder.current_segment.trace_id

  XRay.recorder.end_subsegment

  XRay.recorder.end_segment if no_segment
rescue StandardError => e
  log.error e
  raise e
end