Sha256: 43e77359cfd34bf6a1eeadca1083bc86746771d87b710df4930afd155685e34e

Contents?: true

Size: 1.55 KB

Versions: 32

Compression:

Stored size: 1.55 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 &&
            is_valid_payload?(incoming_payload) &&
            is_supported_version?(incoming_payload) &&
            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

      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
    end
  end
end

Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
newrelic_rpm-4.2.0.334 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-4.1.0.333 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-4.0.0.332 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-3.18.1.330 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-3.18.0.329 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-3.17.2.327 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-3.17.1.326 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-3.17.0.325 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-3.16.3.323 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-3.16.2.321 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-3.16.1.320 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-3.16.0.318 lib/new_relic/agent/synthetics_monitor.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.15.2.317/lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-3.15.2.317 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-3.15.1.316 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-3.15.0.314 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-3.14.3.313 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-3.14.2.312 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-3.14.1.311 lib/new_relic/agent/synthetics_monitor.rb
newrelic_rpm-3.14.0.305 lib/new_relic/agent/synthetics_monitor.rb