Class: SaloPulse::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/salopulse/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



8
9
10
# File 'lib/salopulse/middleware.rb', line 8

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/salopulse/middleware.rb', line 12

def call(env)
  start_monotonic = monotonic_time

  status, headers, body = @app.call(env)

  duration_ms = ((monotonic_time - start_monotonic) * 1000.0).round(2)

  begin
    event = build_event(env, status, duration_ms)
    SaloPulse::Client.send_event(event) if event
  rescue StandardError => e
    log_middleware_error(e)
  end

  [status, headers, body]
end