Method: TingYun::Agent::CrossAppMonitor#register_event_listeners

Defined in:
lib/ting_yun/agent/cross_app/cross_app_monitor.rb

#register_event_listeners(events) ⇒ Object

Expected sequence of events:

:before_call will save our cross application request id to the thread
:after_call will write our response headers/metrics and clean up the thread


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ting_yun/agent/cross_app/cross_app_monitor.rb', line 26

def register_event_listeners(events)
  TingYun::Agent.logger.debug("Wiring up Cross Application Tracing to events after finished configuring")

  events.subscribe(:cross_app_before_call) do |env| #THREAD_LOCAL_ACCESS
    if TingYun::Agent::CrossAppTracing.cross_app_enabled?
      state = TingYun::Agent::TransactionState.tl_get
      state.save_referring_transaction_info(env[TY_ID_HEADER].split(';')) if env[TY_ID_HEADER]
    end
  end

  events.subscribe(:cross_app_after_call) do |_status_code, headers, _body| #THREAD_LOCAL_ACCESS
    insert_response_header(headers) if TingYun::Agent::CrossAppTracing.cross_app_enabled?
  end

end