Class: NewRelic::Agent::SyntheticsMonitor
- Inherits:
-
InboundRequestMonitor
- Object
- InboundRequestMonitor
- NewRelic::Agent::SyntheticsMonitor
- Defined in:
- lib/new_relic/agent/monitors/synthetics_monitor.rb
Constant Summary collapse
- SYNTHETICS_HEADER_KEY =
'HTTP_X_NEWRELIC_SYNTHETICS'.freeze
- SUPPORTED_VERSION =
1
- EXPECTED_PAYLOAD_LENGTH =
5
Instance Attribute Summary
Attributes inherited from InboundRequestMonitor
Class Method Summary collapse
- .is_supported_version?(incoming_payload) ⇒ Boolean
- .is_trusted?(incoming_payload) ⇒ Boolean
- .is_valid_payload?(incoming_payload) ⇒ Boolean
- .reject_messaging_synthetics_header(headers) ⇒ Object
Instance Method Summary collapse
-
#on_before_call(request) ⇒ Object
THREAD_LOCAL_ACCESS.
- #on_finished_configuring(events) ⇒ Object
Methods inherited from InboundRequestMonitor
#deserialize_header, #initialize, #setup_obfuscator
Constructor Details
This class inherits a constructor from NewRelic::Agent::InboundRequestMonitor
Class Method Details
.is_supported_version?(incoming_payload) ⇒ Boolean
34 35 36 |
# File 'lib/new_relic/agent/monitors/synthetics_monitor.rb', line 34 def is_supported_version?(incoming_payload) incoming_payload.first == SUPPORTED_VERSION end |
.is_trusted?(incoming_payload) ⇒ Boolean
38 39 40 41 |
# File 'lib/new_relic/agent/monitors/synthetics_monitor.rb', line 38 def is_trusted?(incoming_payload) account_id = incoming_payload[1] Agent.config[:trusted_account_ids].include?(account_id) end |
.is_valid_payload?(incoming_payload) ⇒ Boolean
43 44 45 |
# File 'lib/new_relic/agent/monitors/synthetics_monitor.rb', line 43 def is_valid_payload?(incoming_payload) incoming_payload.length == EXPECTED_PAYLOAD_LENGTH end |
.reject_messaging_synthetics_header(headers) ⇒ Object
47 48 49 |
# File 'lib/new_relic/agent/monitors/synthetics_monitor.rb', line 47 def reject_messaging_synthetics_header(headers) headers.reject { |k, _| k == CrossAppTracing::NR_MESSAGE_BROKER_SYNTHETICS_HEADER } end |
Instance Method Details
#on_before_call(request) ⇒ Object
THREAD_LOCAL_ACCESS
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/new_relic/agent/monitors/synthetics_monitor.rb', line 17 def on_before_call(request) # THREAD_LOCAL_ACCESS encoded_header = request[SYNTHETICS_HEADER_KEY] return unless encoded_header incoming_payload = deserialize_header(encoded_header, SYNTHETICS_HEADER_KEY) return unless incoming_payload && SyntheticsMonitor.is_valid_payload?(incoming_payload) && SyntheticsMonitor.is_supported_version?(incoming_payload) && SyntheticsMonitor.is_trusted?(incoming_payload) txn = Tracer.current_transaction txn.raw_synthetics_header = encoded_header txn.synthetics_payload = incoming_payload end |
#on_finished_configuring(events) ⇒ Object
13 14 15 |
# File 'lib/new_relic/agent/monitors/synthetics_monitor.rb', line 13 def on_finished_configuring(events) events.subscribe(:before_call, &method(:on_before_call)) end |