Sha256: bf68561f2ad5b7ae94ec0ce14a362bb04b89d8a1559cb64bfddcd258116780bc

Contents?: true

Size: 1.4 KB

Versions: 270

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

require "rack"

module Appsignal
  # @api private
  module Rack
    class GenericInstrumentation
      def initialize(app, options = {})
        Appsignal.logger.debug "Initializing Appsignal::Rack::GenericInstrumentation"
        @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 = ::Rack::Request.new(env)
        transaction = Appsignal::Transaction.create(
          SecureRandom.uuid,
          Appsignal::Transaction::HTTP_REQUEST,
          request
        )
        begin
          Appsignal.instrument("process_action.generic") do
            @app.call(env)
          end
        rescue Exception => error # rubocop:disable Lint/RescueException
          transaction.set_error(error)
          raise error
        ensure
          if env["appsignal.route"]
            transaction.set_action_if_nil(env["appsignal.route"])
          else
            transaction.set_action_if_nil("unknown")
          end
          transaction.set_metadata("path", request.path)
          transaction.set_metadata("method", request.request_method)
          transaction.set_http_or_background_queue_start
          Appsignal::Transaction.complete_current!
        end
      end
    end
  end
end

Version data entries

270 entries across 270 versions & 1 rubygems

Version Path
appsignal-3.1.2-java lib/appsignal/rack/generic_instrumentation.rb
appsignal-3.1.2 lib/appsignal/rack/generic_instrumentation.rb
appsignal-3.1.1-java lib/appsignal/rack/generic_instrumentation.rb
appsignal-3.1.1 lib/appsignal/rack/generic_instrumentation.rb
appsignal-3.1.0-java lib/appsignal/rack/generic_instrumentation.rb
appsignal-3.1.0 lib/appsignal/rack/generic_instrumentation.rb
appsignal-3.0.27-java lib/appsignal/rack/generic_instrumentation.rb
appsignal-3.0.27 lib/appsignal/rack/generic_instrumentation.rb
appsignal-3.0.26-java lib/appsignal/rack/generic_instrumentation.rb
appsignal-3.0.26 lib/appsignal/rack/generic_instrumentation.rb
appsignal-3.0.25-java lib/appsignal/rack/generic_instrumentation.rb
appsignal-3.0.25 lib/appsignal/rack/generic_instrumentation.rb
appsignal-3.0.24-java lib/appsignal/rack/generic_instrumentation.rb
appsignal-3.0.24 lib/appsignal/rack/generic_instrumentation.rb
appsignal-3.0.23-java lib/appsignal/rack/generic_instrumentation.rb
appsignal-3.0.23 lib/appsignal/rack/generic_instrumentation.rb
appsignal-3.0.22-java lib/appsignal/rack/generic_instrumentation.rb
appsignal-3.0.22 lib/appsignal/rack/generic_instrumentation.rb
appsignal-3.0.21-java lib/appsignal/rack/generic_instrumentation.rb
appsignal-3.0.21 lib/appsignal/rack/generic_instrumentation.rb