Sha256: 2a4468f6b0ead56b9ca7f001fbdee69cd8881f9da0dafd4ce0e8eadaf034f087

Contents?: true

Size: 1.54 KB

Versions: 35

Compression:

Stored size: 1.54 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/transaction_state'
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

35 entries across 35 versions & 2 rubygems

Version Path
newrelic_rpm-5.7.0.350 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-5.6.0.349 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-5.5.0.348 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-5.4.0.347 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-5.3.0.346 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-5.2.0.345 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-5.1.0.344 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-5.0.0.342 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-4.8.0.341 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-4.7.1.340 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-4.7.0.339 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-4.6.0.338 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-4.5.0.337 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-4.4.0.336 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-4.3.0.335 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-4.2.0.334 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-4.1.0.333 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-4.0.0.332 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-3.18.1.330 lib/new_relic/rack/agent_middleware.rb
newrelic_rpm-3.18.0.329 lib/new_relic/rack/agent_middleware.rb