Class: Wurk::Sentry::Middleware

Inherits:
Object
  • Object
show all
Includes:
Middleware::ServerMiddleware
Defined in:
lib/wurk/sentry/middleware.rb

Overview

Server middleware: scopes every job for Sentry, and reports the job's terminal failure while that scope is still open.

The same failure then reaches config.error_handlers as "Job raised exception"; the middleware marks every exception it saw (captured or not) so ErrorHandler leaves it alone and reports only the job failures that never passed through here.

The exception is always re-raised: Wurk's retry pipeline, not this middleware, owns the failure.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(report_after_attempts = nil) ⇒ Middleware

Returns a new instance of Middleware.



24
25
26
# File 'lib/wurk/sentry/middleware.rb', line 24

def initialize(report_after_attempts = nil)
  @report_after_attempts = report_after_attempts
end

Instance Attribute Details

#config ⇒ Object Originally defined in module Middleware::ServerMiddleware

Returns the value of attribute config.

Instance Method Details

#call(instance, job, queue, &block) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/wurk/sentry/middleware.rb', line 28

def call(instance, job, queue, &block)
  return yield unless Wurk::Sentry.enabled?

  # The previous job's exception (with its backtrace and anything it
  # references) would otherwise stay pinned in this thread's slots until
  # the next failure here replaced it. Both handshakes are within one job.
  ErrorHandler.forget_thread!
  # Each Processor owns a thread, and Sentry's hub is thread-local.
  # Without this the worker thread starts from an empty hub and the
  # scope set below is invisible to the capture.
  ::Sentry.clone_hub_to_current_thread

  ::Sentry.with_scope do |scope|
    JobContext.apply(scope, job, queue)
    monitor(instance, job, &block)
  end
end

#logger ⇒ Object Originally defined in module Middleware::ServerMiddleware

#redis(idempotent: false) ⇒ Object Originally defined in module Middleware::ServerMiddleware

#redis_pool ⇒ Object Originally defined in module Middleware::ServerMiddleware