[sidekiq] unhandled errors not captured
Issue Description
A customer reported issues sending unhandled errors to Sentry using the sidekiq SDK. While events sent with captureException were sent correctly.
The customer believes the issue is related to the timing of initializations: The error handler that is added by sentry-sidekiq is being cleared later by Sidekiq (which appears to have been introduced in v6.5.x), so while the middleware is working, the error handler isn't being called.
This is where the sentry-sidekiq error handler is added: https://github.com/getsentry/sentry-ruby/blob/353a813378e708657ca83336947720406b4d9bc4/sentry-sidekiq/lib/sentry-sidekiq.rb#L28 This is where Sidekick is clearling all the error handlers: https://github.com/mperham/sidekiq/blob/ea9c86ff5052fff310e83cf51d020771795bb4b6/lib/sidekiq/cli.rb#L26
We just got a workaround in place in our staging environment by adding the error handler directly from our own sidekiq.rb initializer
Sidekiq.configure_server do |config|
# ...
if config.error_handlers.none?(Sentry::Sidekiq::ErrorHandler)
config.error_handlers << Sentry::Sidekiq::ErrorHandler.new
end
# ...
end
Reproduction Steps
NA
Expected Behavior
Unhandled execption to be sent to Sentryexception
Actual Behavior
No event is sent.
Ruby Version
--
SDK Version
5.4.2
Integration and Its Version
No response
Sentry Config
Sentry.init do |config|
filter = ActiveSupport::ParameterFilter.new(Rails.application.config.filter_parameters)
config.before_send = lambda { |event, _hint| filter.filter(event.to_hash) }
config.breadcrumbs_logger = %i[http_logger monotonic_active_support_logger]
config.send_default_pii = false
config.dsn = ENV['SENTRY_RAVEN_DSN'] if ENV['DISABLE_SENTRY'].blank?
if !Rails.env.production? && ENV['HEROKU_APP_NAME'].present?
config.enabled_environments = [ENV['HEROKU_APP_NAME']]
config.environment = ENV['HEROKU_APP_NAME']
else
config.enabled_environments = %w[staging production]
config.environment = Rails.env
end
config.release = ENV['RELEASE_VERSION'] || ENV['SOURCE_VERSION']
# temporarily enable debug for BUAPP-48809
config.debug = true
Environment: sentry-rails (5.4.2) railties (>= 5.0) sentry-ruby (~> 5.4.2) sentry-ruby (5.4.2) concurrent-ruby (~> 1.0, >= 1.0.2) sentry-sidekiq (5.4.2) sentry-ruby (~> 5.4.2) sidekiq (>= 3.0)