class NewRelic::Agent::SyntheticsMonitor

Constants

EXPECTED_PAYLOAD_LENGTH
SUPPORTED_VERSION
SYNTHETICS_HEADER_KEY
SYNTHETICS_INFO_HEADER_KEY

Public Class Methods

is_supported_version?(incoming_payload) click to toggle source
# File lib/new_relic/agent/monitors/synthetics_monitor.rb, line 45
def is_supported_version?(incoming_payload)
  incoming_payload.first == SUPPORTED_VERSION
end
is_trusted?(incoming_payload) click to toggle source
# File lib/new_relic/agent/monitors/synthetics_monitor.rb, line 49
def is_trusted?(incoming_payload)
  account_id = incoming_payload[1]
  Agent.config[:trusted_account_ids].include?(account_id)
end
is_valid_payload?(incoming_payload) click to toggle source
# File lib/new_relic/agent/monitors/synthetics_monitor.rb, line 54
def is_valid_payload?(incoming_payload)
  incoming_payload.length == EXPECTED_PAYLOAD_LENGTH
end
reject_messaging_synthetics_header(headers) click to toggle source
# File lib/new_relic/agent/monitors/synthetics_monitor.rb, line 58
def reject_messaging_synthetics_header(headers)
  headers.reject { |k, _| k == CrossAppTracing::NR_MESSAGE_BROKER_SYNTHETICS_HEADER }
end

Public Instance Methods

load_json(header, key) click to toggle source
# File lib/new_relic/agent/monitors/synthetics_monitor.rb, line 37
def load_json(header, key)
  ::JSON.load(header)
rescue => err
  NewRelic::Agent.logger.debug("Failure loading json header '#{key}' in #{self.class}, #{err.class}, #{err.message}")
  nil
end
on_before_call(request) click to toggle source
# File lib/new_relic/agent/monitors/synthetics_monitor.rb, line 18
def on_before_call(request) # THREAD_LOCAL_ACCESS
  encoded_header = request[SYNTHETICS_HEADER_KEY]
  info_header = request[SYNTHETICS_INFO_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.raw_synthetics_info_header = info_header
  txn.synthetics_payload = incoming_payload
  txn.synthetics_info_payload = load_json(info_header, SYNTHETICS_INFO_HEADER_KEY)
end
on_finished_configuring(events) click to toggle source
# File lib/new_relic/agent/monitors/synthetics_monitor.rb, line 14
def on_finished_configuring(events)
  events.subscribe(:before_call, &method(:on_before_call))
end