Sha256: b38b226473633120a934e4248fac0aeb8b2a013745a081d18affa70d4e03568f

Contents?: true

Size: 1.3 KB

Versions: 46

Compression:

Stored size: 1.3 KB

Contents

require 'rack'

module Appsignal
  module Rack
    class GenericInstrumentation
      def initialize(app, options = {})
        Appsignal.logger.debug 'Initializing Appsignal::Rack::GenericInstrumentation'
        @app, @options = app, 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
          ActiveSupport::Notifications.instrument('process_action.generic') do
            @app.call(env)
          end
        rescue => error
          transaction.set_error(error)
          raise error
        ensure
          if env['appsignal.route']
            transaction.set_action(env['appsignal.route'])
          else
            transaction.set_action('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

46 entries across 46 versions & 1 rubygems

Version Path
appsignal-1.3.6 lib/appsignal/rack/generic_instrumentation.rb
appsignal-1.3.6.beta.1 lib/appsignal/rack/generic_instrumentation.rb
appsignal-1.3.5 lib/appsignal/rack/generic_instrumentation.rb
appsignal-1.3.5.beta.1 lib/appsignal/rack/generic_instrumentation.rb
appsignal-1.3.4 lib/appsignal/rack/generic_instrumentation.rb
appsignal-1.3.3 lib/appsignal/rack/generic_instrumentation.rb
appsignal-1.4.0.alpha.2 lib/appsignal/rack/generic_instrumentation.rb
appsignal-1.4.0.alpha.1 lib/appsignal/rack/generic_instrumentation.rb
appsignal-1.3.2 lib/appsignal/rack/generic_instrumentation.rb
appsignal-1.3.1 lib/appsignal/rack/generic_instrumentation.rb
appsignal-1.3.0 lib/appsignal/rack/generic_instrumentation.rb
appsignal-1.3.0.beta.3 lib/appsignal/rack/generic_instrumentation.rb
appsignal-1.3.0.beta.2 lib/appsignal/rack/generic_instrumentation.rb
appsignal-1.3.0.beta.1 lib/appsignal/rack/generic_instrumentation.rb
appsignal-1.2.5 lib/appsignal/rack/generic_instrumentation.rb
appsignal-1.2.4 lib/appsignal/rack/generic_instrumentation.rb
appsignal-1.2.4.beta.4 lib/appsignal/rack/generic_instrumentation.rb
appsignal-1.2.4.beta.3 lib/appsignal/rack/generic_instrumentation.rb
appsignal-1.2.4.beta.2 lib/appsignal/rack/generic_instrumentation.rb
appsignal-1.2.4.beta.1 lib/appsignal/rack/generic_instrumentation.rb