Module: Wurk::Sentry

Defined in:
lib/wurk/sentry.rb,
lib/wurk/sentry/middleware.rb,
lib/wurk/sentry/job_context.rb,
lib/wurk/sentry/retry_policy.rb,
lib/wurk/sentry/death_handler.rb,
lib/wurk/sentry/error_handler.rb

Overview

Opt-in Sentry integration. Not loaded by require "wurk" — pull it in explicitly and install it on the server config:

# config/initializers/wurk.rb
require "wurk/sentry"

Wurk.configure_server do |config|
Wurk::Sentry.install!(config)
end

This exists because sentry-sidekiq cannot be used with Wurk: its gemspec declares add_dependency "sidekiq", so Bundler installs real Sidekiq alongside Wurk and require "sidekiq" loads a broken hybrid. (The ecosystem/sidekiq-shim/ git source is the escape hatch for gems you must keep; see docs/sentry.md.)

sentry-ruby is not a runtime dependency — it is never required here, and every call site is guarded by Sentry.enabled?. Loading this file in an app without sentry-ruby, or before Sentry.init has run, is a no-op.

See docs/sentry.md.

Defined Under Namespace

Modules: JobContext, RetryPolicy Classes: DeathHandler, ErrorHandler, Middleware

Constant Summary collapse

CONTROL_FLOW_ERRORS =

Sentry matches an excluded name by ancestry, so Handled also covers JobRetry::Skip, its subclass.

%w[Wurk::JobRetry::Handled Wurk::Shutdown].freeze

Class Method Summary collapse

Class Method Details

.enabled? ⇒ Boolean

True only when sentry-ruby is loaded and Sentry.init has run. Guards every call into the SDK so the integration is inert by default.

Returns:

  • (Boolean)


74
75
76
# File 'lib/wurk/sentry.rb', line 74

def enabled?
  defined?(::Sentry) && ::Sentry.respond_to?(:initialized?) && ::Sentry.initialized?
end

.excluded_exceptions ⇒ Object

The retry machinery's own signals, for a Sentry setup that does not run install! (the web process, a Sentry.init that runs first):

config.excluded_exceptions += Wurk::Sentry.excluded_exceptions

A Rails.error subscriber sees these cross the reloader on every failed attempt, as it does under Sidekiq.



43
# File 'lib/wurk/sentry.rb', line 43

def excluded_exceptions = CONTROL_FLOW_ERRORS

.install!(config = Wurk.configuration, filter_transport_errors: true, filtered_error_classes: nil, report_after_attempts: nil) ⇒ Wurk::Configuration

Registers the server middleware and the error handler. Idempotent: Chain#add dedupes by class, and a previously-installed ErrorHandler is replaced rather than stacked, so calling this twice (or calling it after an auto-install) never doubles a report.

Parameters:

  • config (Wurk::Configuration) (defaults to: Wurk.configuration) —

    usually the block argument of Wurk.configure_server.

  • filter_transport_errors (Boolean) (defaults to: true) —

    drop self-healing Redis / connection-pool errors instead of reporting them. See Wurk::Sentry::ErrorHandler::DEFAULT_FILTERED_ERROR_CLASSES.

  • filtered_error_classes (Array<Class>, nil) (defaults to: nil) —

    replaces the default filter list. Extend it with Wurk::Sentry::ErrorHandler::DEFAULT_FILTERED_ERROR_CLASSES + [MyError].

  • report_after_attempts (Integer, nil) (defaults to: nil) —

    also report the failure of this attempt (1 is the first run), on top of the terminal one. By default a job on the 25-retry schedule first alerts ~21 days in.

Returns:



62
63
64
65
66
67
68
69
70
# File 'lib/wurk/sentry.rb', line 62

def install!(config = Wurk.configuration, filter_transport_errors: true, filtered_error_classes: nil,
             report_after_attempts: nil)
  validate_attempts!(report_after_attempts)
  config.server_middleware.add(Middleware, report_after_attempts)
  install_error_handler(config, filter_transport_errors, filtered_error_classes, report_after_attempts)
  install_death_handler(config)
  exclude_control_flow_errors
  config
end