Sha256: 578d3db623ad7d7febdfe5f8cfb7734ef734c2e325420c68827a2784d0eee492

Contents?: true

Size: 1.83 KB

Versions: 15

Compression:

Stored size: 1.83 KB

Contents

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

require 'new_relic/agent/inbound_request_monitor'

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)

        state = NewRelic::Agent::TransactionState.tl_get
        txn = state.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]
          NewRelic::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 == NewRelic::Agent::CrossAppTracing::NR_MESSAGE_BROKER_SYNTHETICS_HEADER}
        end

      end

    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
newrelic_rpm-5.7.0.350 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-5.6.0.349 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-5.5.0.348 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-5.4.0.347 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-5.3.0.346 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-5.2.0.345 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-5.1.0.344 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-5.0.0.342 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-4.8.0.341 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-4.7.1.340 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-4.7.0.339 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-4.6.0.338 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-4.5.0.337 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-4.4.0.336 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-4.3.0.335 lib/new_relic/agent/synthetics_monitor.rb