Class: Attio::Observability::Middleware
- Inherits:
-
Object
- Object
- Attio::Observability::Middleware
- Defined in:
- lib/attio/observability.rb
Overview
Middleware for automatic instrumentation
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, instrumentation) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, instrumentation) ⇒ Middleware
Returns a new instance of Middleware.
391 392 393 394 |
# File 'lib/attio/observability.rb', line 391 def initialize(app, instrumentation) @app = app @instrumentation = instrumentation end |
Instance Method Details
#call(env) ⇒ Object
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'lib/attio/observability.rb', line 396 def call(env) start_time = Time.now method = env[:method] path = env[:url].path begin response = @app.call(env) @instrumentation.record_api_call( method: method, path: path, duration: Time.now - start_time, status: response.status ) response rescue StandardError => e @instrumentation.record_api_call( method: method, path: path, duration: Time.now - start_time, error: e ) raise end end |