Module: OneApm::Agent::CrossAppTracingMessage
- Defined in:
- lib/one_apm/agent/cross_app/cross_app_tracing_message.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- OA_ID_MESSAGE_HEADER =
'BlueWareID'
- OA_TXN_MESSAGE_HEADER =
'BlueWareTransaction'
- OA_SYNTHETICS_MESSAGE_HEADER =
'BlueWareSynthetics'
Class Method Summary collapse
-
.cross_app_enabled? ⇒ Boolean
Return
true
if cross app tracing is enabled in the config. -
.cross_app_encoding_key ⇒ Object
Fetcher for the cross app encoding key.
- .cross_app_id ⇒ Object
- .cross_application_tracer_enabled? ⇒ Boolean
- .finish_trace(state, t0, segment, request, metrics) ⇒ Object
- .inject_rpc_request_headers(state, rpc_request) ⇒ Object
- .obfuscator ⇒ Object
-
.process_request(message) ⇒ Object
TODO: just stub.
- .request_data(state) ⇒ Object
- .start_trace(state, t0, rpc_request) ⇒ Object
- .valid_cross_process_id? ⇒ Boolean
- .valid_encoding_key? ⇒ Boolean
Class Method Details
.cross_app_enabled? ⇒ Boolean
Return true
if cross app tracing is enabled in the config.
99 100 101 102 103 |
# File 'lib/one_apm/agent/cross_app/cross_app_tracing_message.rb', line 99 def cross_app_enabled? valid_cross_process_id? && valid_encoding_key? && cross_application_tracer_enabled? end |
.cross_app_encoding_key ⇒ Object
Fetcher for the cross app encoding key. Raises a OneApm::Agent::CrossAppTracingMessage::Error if the key isn’t configured.
119 120 121 122 |
# File 'lib/one_apm/agent/cross_app/cross_app_tracing_message.rb', line 119 def cross_app_encoding_key OneApm::Manager.config[:encoding_key] or raise OneApm::Agent::CrossAppTracingMessage::Error, "No encoding_key set." end |
.cross_app_id ⇒ Object
50 51 52 53 |
# File 'lib/one_apm/agent/cross_app/cross_app_tracing_message.rb', line 50 def cross_app_id OneApm::Manager.config[:cross_process_id] or raise OneApm::Agent::CrossAppTracingMessage::Error, "no cross app ID configured" end |
.cross_application_tracer_enabled? ⇒ Boolean
113 114 115 |
# File 'lib/one_apm/agent/cross_app/cross_app_tracing_message.rb', line 113 def cross_application_tracer_enabled? OneApm::Manager.config[:"cross_application_tracer.enabled"] end |
.finish_trace(state, t0, segment, request, metrics) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/one_apm/agent/cross_app/cross_app_tracing_message.rb', line 68 def finish_trace(state, t0, segment, request, metrics) unless t0 OneApm::Manager.logger.error("RPC request trace finished without start time. This is probably an agent bug.") return end t1 = Time.now duration = t1.to_f - t0.to_f begin if request scoped_metric, *other_metrics = metrics OneApm::Manager.agent.stats_engine.record_scoped_and_unscoped_metrics(state, scoped_metric, nil, duration) if segment segment.name = scoped_metric end end ensure # If we have a segment, always pop the traced method stack to avoid # an inconsistent state, which prevents tracing of whole transaction. if segment stack = state.traced_method_stack stack.pop_frame(state, segment, scoped_metric, t1) end end rescue OneApm::Agent::CrossAppTracingMessage::Error => err OneApm::Manager.logger.debug "while cross app tracing", err rescue => err OneApm::Manager.logger.error "Uncaught exception while finishing an RPC request trace", err end |
.inject_rpc_request_headers(state, rpc_request) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/one_apm/agent/cross_app/cross_app_tracing_message.rb', line 34 def inject_rpc_request_headers state, rpc_request txn_guid = state.request_guid txn = state.current_transaction if txn trip_id = txn.cat_trip_id(state) path_hash = txn.cat_path_hash(state) if txn.raw_synthetics_header rpc_request[OA_SYNTHETICS_MESSAGE_HEADER] = txn.raw_synthetics_header end end rpc_request[OA_ID_MESSAGE_HEADER] = cross_app_id rpc_request[OA_TXN_MESSAGE_HEADER] = [txn_guid, true, trip_id, path_hash, ''] rescue OneApm::Agent::CrossAppTracingMessage::Error => err #TODO OneApm::Manager.logger.debug "Not injecting x-process header", err end |
.obfuscator ⇒ Object
124 125 126 |
# File 'lib/one_apm/agent/cross_app/cross_app_tracing_message.rb', line 124 def obfuscator @obfuscator ||= OneApm::Agent::Obfuscator.new(cross_app_encoding_key) end |
.process_request(message) ⇒ Object
TODO: just stub
30 31 32 |
# File 'lib/one_apm/agent/cross_app/cross_app_tracing_message.rb', line 30 def process_request OneApm::Manager.logger.debug "Thrift Process Message: #{}" end |
.request_data(state) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/one_apm/agent/cross_app/cross_app_tracing_message.rb', line 19 def request_data(state) rpc_request = {} inject_rpc_request_headers(state, rpc_request) if cross_app_enabled? json_rpc_request = OneApm::JSONWrapper.dump(rpc_request) # OneApm::Manager.logger.debug "Thrift Header Message: #{json_rpc_request}" obfuscator.obfuscate(json_rpc_request) rescue OneApm::Agent::CrossAppTracingMessage::Error => err OneApm::Manager.logger.debug "Not injecting x-process header", err end |
.start_trace(state, t0, rpc_request) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/one_apm/agent/cross_app/cross_app_tracing_message.rb', line 55 def start_trace(state, t0, rpc_request) state.is_cross_app_caller = true stack = state.traced_method_stack segment = stack.push_frame(state, :rpc_request, t0) return segment rescue => err OneApm::Manager.logger.error "Uncaught exception while tracing RPC request", err return nil rescue Exception => e OneApm::Manager.logger.debug "Unexpected exception raised while tracing RPC request", e raise e end |