Class: Bugwatch::Middleware
- Inherits:
-
Object
- Object
- Bugwatch::Middleware
- Defined in:
- lib/bugwatch/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
3 4 5 |
# File 'lib/bugwatch/middleware.rb', line 3 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bugwatch/middleware.rb', line 7 def call(env) if Bugwatch.skip_tracking? || skip_path?(env) return @app.call(env) end start = Process.clock_gettime(Process::CLOCK_MONOTONIC) BreadcrumbCollector.clear UserContext.clear config = Bugwatch.configuration collecting = config.enable_db_tracking && (rand < config.db_sample_rate) DbTracker.start_request(collecting: collecting) begin status, headers, body = @app.call(env) record_transaction(env, status, start) [status, headers, body] rescue Exception => e # rubocop:disable Lint/RescueException duration_ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start) * 1000).round unless Bugwatch.configuration.ignore?(e) payload = ErrorBuilder.new(e, env).build payload[:duration_ms] = duration_ms Notification.new(payload).deliver end record_transaction(env, 500, start) raise ensure DbTracker.clear end end |