Sha256: 3feda0883e0fd9543e247348eb39fe7dfc41fb9d55ccc48ba0e6bf1e1091a9b5

Contents?: true

Size: 1.71 KB

Versions: 11

Compression:

Stored size: 1.71 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.

module NewRelic
  module Agent
    class SyntheticsMonitor < InboundRequestMonitor
      SYNTHETICS_HEADER_KEY  = 'HTTP_X_NEWRELIC_SYNTHETICS'.freeze

      SUPPORTED_VERSION = 1
      EXPECTED_PAYLOAD_LENGTH = 5

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

      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

      class << self

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

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

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

        def reject_messaging_synthetics_header headers
          headers.reject {|k,_| k == CrossAppTracing::NR_MESSAGE_BROKER_SYNTHETICS_HEADER}
        end

      end

    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
newrelic_rpm-8.2.0 lib/new_relic/agent/monitors/synthetics_monitor.rb
newrelic_rpm-8.1.0 lib/new_relic/agent/monitors/synthetics_monitor.rb
newrelic_rpm-8.0.0 lib/new_relic/agent/monitors/synthetics_monitor.rb
newrelic_rpm-7.2.0 lib/new_relic/agent/monitors/synthetics_monitor.rb
newrelic_rpm-7.1.0 lib/new_relic/agent/monitors/synthetics_monitor.rb
newrelic_rpm-7.0.0 lib/new_relic/agent/monitors/synthetics_monitor.rb
newrelic_rpm-6.15.0 lib/new_relic/agent/monitors/synthetics_monitor.rb
newrelic_rpm-6.14.0 lib/new_relic/agent/monitors/synthetics_monitor.rb
newrelic_rpm-6.13.1 lib/new_relic/agent/monitors/synthetics_monitor.rb
newrelic_rpm-6.13.0 lib/new_relic/agent/monitors/synthetics_monitor.rb
newrelic_rpm-6.12.0.367 lib/new_relic/agent/monitors/synthetics_monitor.rb