Sha256: 2674ab584fb42dbe8693311c59e8b8b86bfe7d4ca83b4b2313f20f39608f220f

Contents?: true

Size: 1.62 KB

Versions: 82

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

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 Exception => error # rubocop:disable Lint/RescueException
          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)
          begin
            transaction.set_metadata("method", request.request_method)
          rescue => error
            Appsignal.logger.error("Unable to report HTTP request method: '#{error}'")
          end
          Appsignal::Transaction.complete_current!
        end
      end

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

Version data entries

82 entries across 82 versions & 1 rubygems

Version Path
appsignal-3.5.4-java lib/appsignal/rack/rails_instrumentation.rb
appsignal-3.5.4 lib/appsignal/rack/rails_instrumentation.rb
appsignal-3.5.3-java lib/appsignal/rack/rails_instrumentation.rb
appsignal-3.5.3 lib/appsignal/rack/rails_instrumentation.rb
appsignal-3.5.2-java lib/appsignal/rack/rails_instrumentation.rb
appsignal-3.5.2 lib/appsignal/rack/rails_instrumentation.rb
appsignal-3.5.1-java lib/appsignal/rack/rails_instrumentation.rb
appsignal-3.5.1 lib/appsignal/rack/rails_instrumentation.rb
appsignal-3.5.0-java lib/appsignal/rack/rails_instrumentation.rb
appsignal-3.5.0 lib/appsignal/rack/rails_instrumentation.rb
appsignal-3.4.16-java lib/appsignal/rack/rails_instrumentation.rb
appsignal-3.4.16 lib/appsignal/rack/rails_instrumentation.rb
appsignal-3.4.15-java lib/appsignal/rack/rails_instrumentation.rb
appsignal-3.4.15 lib/appsignal/rack/rails_instrumentation.rb
appsignal-3.4.14-java lib/appsignal/rack/rails_instrumentation.rb
appsignal-3.4.14 lib/appsignal/rack/rails_instrumentation.rb
appsignal-3.4.13-java lib/appsignal/rack/rails_instrumentation.rb
appsignal-3.4.13 lib/appsignal/rack/rails_instrumentation.rb
appsignal-3.4.12-java lib/appsignal/rack/rails_instrumentation.rb
appsignal-3.4.12 lib/appsignal/rack/rails_instrumentation.rb