Class: Appsignal::Rack::GenericInstrumentation

Inherits:
Object
  • Object
show all
Defined in:
lib/appsignal/rack/generic_instrumentation.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ GenericInstrumentation

Returns a new instance of GenericInstrumentation.


6
7
8
9
# File 'lib/appsignal/rack/generic_instrumentation.rb', line 6

def initialize(app, options = {})
  Appsignal.logger.debug 'Initializing Appsignal::Rack::GenericInstrumentation'
  @app, @options = app, options
end

Instance Method Details

#call(env) ⇒ Object


11
12
13
14
15
16
17
# File 'lib/appsignal/rack/generic_instrumentation.rb', line 11

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

#call_with_appsignal_monitoring(env) ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/appsignal/rack/generic_instrumentation.rb', line 19

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.('path', request.path)
    transaction.('method', request.request_method)
    transaction.set_http_or_background_queue_start
    Appsignal::Transaction.complete_current!
  end
end