Sha256: d2fd260d9bff6c903d71e43367e9b050501a49cd652d4e62ffbacf44078cd603

Contents?: true

Size: 1.56 KB

Versions: 16

Compression:

Stored size: 1.56 KB

Contents

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

require 'new_relic/agent/tracer'
require 'new_relic/agent/instrumentation/controller_instrumentation'
require 'new_relic/agent/instrumentation/middleware_tracing'

module NewRelic
  module Rack
    class AgentMiddleware
      include Agent::Instrumentation::MiddlewareTracing

      attr_reader :transaction_options, :category, :target

      def initialize(app, options = {})
        @app = app
        @category = :middleware
        @target = self
        @transaction_options = {
          :transaction_name => build_transaction_name
        }
      end

      def build_transaction_name
        prefix = ::NewRelic::Agent::Instrumentation::ControllerInstrumentation::TransactionNamer.prefix_for_category(nil, @category)
        "#{prefix}#{self.class.name}/call"
      end

      # If middleware tracing is disabled, we'll still inject our agent-specific
      # middlewares, and still trace those, but we don't want to capture HTTP
      # response codes, since middleware that's outside of ours might change the
      # response code before it goes back to the client.
      def capture_http_response_code(state, result)
        return if NewRelic::Agent.config[:disable_middleware_instrumentation]

        super
      end

      def capture_response_content_type(state, result)
        return if NewRelic::Agent.config[:disable_middleware_instrumentation]

        super
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
newrelic_rpm-9.4.2 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-9.4.1 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-9.4.0 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-9.3.1 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-9.3.0 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-9.2.2 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-9.2.1 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-9.2.0 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-9.1.0 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-9.0.0 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-8.16.0 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-8.15.0 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-8.14.0 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-8.13.1 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-8.13.0 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-8.12.0 lib/new_relic/rack/agent_middleware.rb