Sha256: f785caef0377c286a209305b29c9f68661c291db0304d6ed90d680772fb585fb

Contents?: true

Size: 1.3 KB

Versions: 42

Compression:

Stored size: 1.3 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
          transaction.set_action_if_nil(env["appsignal.route"] || "unknown")
          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

42 entries across 42 versions & 1 rubygems

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