Class: OneApm::Agent::SyntheticsMonitor

Inherits:
InboundRequestMonitor show all
Defined in:
lib/one_apm/agent/synthetics_monitor.rb

Constant Summary collapse

OA_SYNTHETICS_HEADER_KEY =
'HTTP_X_BLUEWARE_SYNTHETICS'.freeze
OA_SUPPORTED_VERSION =
1
OA_EXPECTED_PAYLOAD_LENGTH =
5

Instance Attribute Summary

Attributes inherited from InboundRequestMonitor

#obfuscator

Instance Method Summary collapse

Methods inherited from InboundRequestMonitor

#deserialize_header, #initialize, #setup_obfuscator

Constructor Details

This class inherits a constructor from OneApm::Agent::InboundRequestMonitor

Instance Method Details

#is_supported_version?(incoming_payload) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/one_apm/agent/synthetics_monitor.rb', line 34

def is_supported_version?(incoming_payload)
  incoming_payload.first == OA_SUPPORTED_VERSION
end

#is_trusted?(incoming_payload) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
# File 'lib/one_apm/agent/synthetics_monitor.rb', line 38

def is_trusted?(incoming_payload)
   = incoming_payload[1]
  OneApm::Manager.config[:trusted_account_ids].include?()
end

#is_valid_payload?(incoming_payload) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/one_apm/agent/synthetics_monitor.rb', line 43

def is_valid_payload?(incoming_payload)
  incoming_payload.length == OA_EXPECTED_PAYLOAD_LENGTH
end

#on_before_call(request) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/one_apm/agent/synthetics_monitor.rb', line 17

def on_before_call(request)
  encoded_header = request[OA_SYNTHETICS_HEADER_KEY]
  return unless encoded_header

  incoming_payload = deserialize_header(encoded_header, OA_SYNTHETICS_HEADER_KEY)

  return unless incoming_payload &&
      is_valid_payload?(incoming_payload) &&
      is_supported_version?(incoming_payload) &&
      is_trusted?(incoming_payload)

  state = OneApm::TransactionState.tl_get
  txn = state.current_transaction
  txn.raw_synthetics_header = encoded_header
  txn.synthetics_payload    = incoming_payload
end

#on_finished_configuring(events) ⇒ Object



13
14
15
# File 'lib/one_apm/agent/synthetics_monitor.rb', line 13

def on_finished_configuring(events)
  events.subscribe(:before_call, &method(:on_before_call))
end