-
Notifications
You must be signed in to change notification settings - Fork 282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rollbar can quietly ignores errors outside of web processes. #183
Comments
Fixes cases where a `Notifier` may have been created prior to the Rollbar initializer calling `Rollbar.configure`. Previously Resque would continue to use this prematurely created `Notifier` and never use the `Configuration` defined by the initializer. See rollbar/rollbar-gem#183
@jonah-williams isn't the initialization/configuration order issues solved with this PR? #170 We fixed this so every Thread create before execute The call to Please let us know which version is failing for you and we'll try to fix it soon :-D. |
@jondeandres it might well be, I was running against |
@jondeandres At a glance I think #170 only resolves one of the two paths above. Deferring the monkey patch to In my case this app had a line something like |
@jonah-williams that wrong configured Perhaps we can reset the notifier when |
@jondeandres exactly, the current thread gets a disabled |
Perhaps we can just don't cache the notifier in |
@jondeandres I don't think that (discarding disabled Updating a |
ok @jonah-williams. I think we can try to reset the notifier in BTW, if the initialization process of a app sends errors to rollbar before the gem is configured, perhaps users should take account of this and prepend the Rollbar configuration before any other one. We'll fix this and check how it works ok? Thank you @jonah-williams! |
Agreed, those early reports are probably a warning sign that should be fixed but it would be great if they didn't also disable reporting more broadly ;) I like moving the call to |
Reset thread's notifier when Rollbar is configured. Fixes #183.
Great, thanks for the fix! |
Released in 1.2.11. Thanks for investigating and reporting this! |
This might be related. |
@pcasaretto is your environment being loaded correctly? Did you check |
I ran a piece of code that raised an exception, and also tried a
Using |
@pcasaretto can you paste that code? I think you are expecting that any exception in the console will be reported. That automatic reports are only done in the middleware, so when there is a request. Exceptions in the console are not reported unless you report them manually. So you should wrap your code with: begin
# your code
rescue => e
Rollbar.error(e)
end |
AH, I see. Thanks for clarifying that. |
Thanks to you @pcasaretto!! |
I was recently surprised to discover that Rollbar (using rollbar-resque) was not reporting errors for failing Resque jobs. Digging further I found that there are a number of cases where the Rollbar gem could surprisingly fail to report errors to the service. In a Rails web process Rollbar avoids this issue thanks to
RollbarMiddleware
making a call toRollbar.reset_notifier!
. However background job processes (Resque, Sidekiq), rake tasks, console sessions, or any other process which loads the Rails environment but does not run middleware can fail to report errors throughout its life.I see two paths to get into this state:
Rollbar.log
prior to the Rollbar initializer callingRollbar.configure
. In my case this was aninfo
level warning in another initializer.Rollbar.configure
. In my case an app had a call to segment.io'sAnalyticsRuby.init
which eventually callsThread.new
.In the first case
Rollbar.log
delegates toRollbar.notifier
which returnsThread.current[:_rollbar_notifier] ||= Notifier.new(self)
(rollbar.rb#L705). In the second caseThread.initialize_with_rollbar
callsRollbar.notifier.scope
. Either way we have a call toRollbar.notifier
which setsThread.current[:_rollbar_notifier]
.The
Notifier
instance created for the thread is passed theRollbar
class as itsparent_notifier
. TheNotifier
then callsparent_notifier.configuration.clone
(rollbar.rb#L42) whereconfiguration
is implemented as@configuration ||= Configuration.new
(rollbar.rb#L683). Now we have aNotifier
for the current thread configured with a newConfiguration
. Since thisConfiguration
has not yet been enabledNotifier.log
will abort due toreturn 'disabled' unless configuration.enabled
(rollbar.rb#L112).In a Rails web process the Rollbar initializer would overwrite any existing
Configuration
when it callsRollbar.configure do ...
. If aNotifier
has already been created as above then it remains disabled and missing any configuration changes from the initializer. That's ok becauseRollbarMiddleware
eventually callsRollbar.reset_notifier!
(rollbar.rb#L16) which callsself.notifier = nil
which leads toThread.current[:_rollbar_notifier] = notifier
and the unconfiguredNotifier
is removed. The next calls toRollbar.notifier
will then create a newNotifier
and inherit theRollbar.configuration
set in the initializer.A similar call to
reset_notifier!
exists in the Rollbar RackBuilder
and Sinatra middleware.Is there a better hook we could use to trigger these
reset_notifier!
calls? Would it be reasonable to always reset the current thread's notifier inRollbar.configure
so that every integration does not need to repeat this setup?As is it seems easy for users of rollbar-resque to miss error reports. At a glance I don't see a call to
reset_notifier!
in https://github.com/allenwei/sidekiq-rollbar either but I'm not familiar with the forking model in use there so maybe it isn't an issue in that case. having added a Rollbar initializer I expected any environment which loads that initializer to be able to successfully report errors to Rollbar. Does that seem like a reasonable expectation, if not maybe we can at least make a readme update?The text was updated successfully, but these errors were encountered: