Sha256: 82ac6a4e7926387a3e4ea51af943a993ec4413c10ab041f8d3cff20d275a7d9e

Contents?: true

Size: 1.4 KB

Versions: 15

Compression:

Stored size: 1.4 KB

Contents

require "rack"

module Appsignal
  # @api private
  module Rack
    class RailsInstrumentation
      def initialize(app, options = {})
        Appsignal.logger.debug "Initializing Appsignal::Rack::RailsInstrumentation"
        @app = app
        @options = options
      end

      def call(env)
        if Appsignal.active?
          call_with_appsignal_monitoring(env)
        else
          @app.call(env)
        end
      end

      def call_with_appsignal_monitoring(env)
        request = ActionDispatch::Request.new(env)
        transaction = Appsignal::Transaction.create(
          request_id(env),
          Appsignal::Transaction::HTTP_REQUEST,
          request,
          :params_method => :filtered_parameters
        )
        begin
          @app.call(env)
        rescue => error
          transaction.set_error(error)
          raise error
        ensure
          controller = env["action_controller.instance"]
          if controller
            transaction.set_action_if_nil("#{controller.class}##{controller.action_name}")
          end
          transaction.set_http_or_background_queue_start
          transaction.set_metadata("path", request.path)
          transaction.set_metadata("method", request.request_method)
          Appsignal::Transaction.complete_current!
        end
      end

      def request_id(env)
        env["action_dispatch.request_id"] || SecureRandom.uuid
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
appsignal-2.3.7 lib/appsignal/rack/rails_instrumentation.rb
appsignal-2.3.6 lib/appsignal/rack/rails_instrumentation.rb
appsignal-2.3.6.beta.1 lib/appsignal/rack/rails_instrumentation.rb
appsignal-2.3.4 lib/appsignal/rack/rails_instrumentation.rb
appsignal-2.3.3 lib/appsignal/rack/rails_instrumentation.rb
appsignal-2.3.3.beta.1 lib/appsignal/rack/rails_instrumentation.rb
appsignal-2.3.2 lib/appsignal/rack/rails_instrumentation.rb
appsignal-2.3.1 lib/appsignal/rack/rails_instrumentation.rb
appsignal-2.3.0 lib/appsignal/rack/rails_instrumentation.rb
appsignal-2.3.0.beta.3 lib/appsignal/rack/rails_instrumentation.rb
appsignal-2.3.0.beta.2 lib/appsignal/rack/rails_instrumentation.rb
appsignal-2.3.0.beta.1 lib/appsignal/rack/rails_instrumentation.rb
appsignal-2.2.1 lib/appsignal/rack/rails_instrumentation.rb
appsignal-2.2.0 lib/appsignal/rack/rails_instrumentation.rb
appsignal-2.2.0.beta.1 lib/appsignal/rack/rails_instrumentation.rb