Skip to content

Confusing error if sentry-sidekiq is imported after Sentry.init #1756

@rgalanakis

Description

@rgalanakis

Issue Description

If sentry-sidekiq is required AFTER Sentry.init has been run, an exception is raised in ErrorHandler, as below (the Sentry.configuration.sidekiq field is nil).
This is because configuration.sidekiq is set in a 'post initialization callback', but once Sentry.init is run, the callbacks won't be run.

This is a really tough one to find and diagnose because it is an exception in an error handler, so of course trying to figure out what happened is very confusing, but obvious in hindsight.

Reproduction Steps

  • require sentry-ruby
  • Sentry.init
  • require sentry-sidekiq
  • Provoke an error
  • An exception is raised:
name:NoMethodError
message:undefined method `report_after_job_retries' for nil:NilClass

if Sentry.configuration.sidekiq.report_after_job_retries && retry_option.is_a?(Integer) && retry_option.positive?

Expected Behavior

Any one of:

  • post_initialization_callbacks are run immediately if Sentry is already initialized
  • The lack of configuration is detected in ErrorHandler, and a clear error is raised
  • The issue with requiring-after-init is detected on import, and a clear error is raised

Actual Behavior

NoMethodError on nil is raised

Ruby Version

All (3.1 tested)

SDK Version

4.8.3

Integration and Its Version

Sidekiq, 4.8.3

Sentry Config

Just need to get Sentry configured in some way:

Sentry.init do |config|
  config.dsn = 'https://examplePublicKey@o0.ingest.sentry.io/0'
end

Metadata

Metadata

Assignees

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions