Bugsnag notifier for EventMachine
The Bugsnag notifier for EventMachine makes it easy to track errors and exceptions inside EventMachine, no matter how many callbacks or deferrables you're using!
Bugsnag EventMachine is not compatible with Bugsnag Ruby v6+
How to Install
-
Add the
bugsnag-em
gem to yourGemfile
gem "bugsnag-em" gem "bugsnag", "~> 5.0" # bugsnag-em is not compatible with bugsnag-ruby v6
-
Install the gem
bundle install
-
Configure the Bugsnag module with your API key
Bugsnag.configure do |config| config.api_key = "YOUR_API_KEY_HERE" end
If you don't configure the api_key, the Bugsnag module will read the
BUGSNAG_API_KEY
environment variable.
Sending custom data with exceptions
The hardest part of handling asynchronous exceptions is to keep track of the context in which they are running. bugsnag-em
uses LSpace under the hood to do so. This enables us to track which contexts callbacks happen in so we don't get muddled by concurrent requests.
To set data for a context, you can use Bugsnag.with
Bugsnag.with(user_id: '123') do
http = EM::HttpRequest.new('http://google.com/').get
http.errback{ raise 'oops' }
...
end
The exception raised in the http callback will be sent to Bugsnag with the user id 123, so you can debug more easily.
Keeping the event loop alive
By default EventMachine terminates the event loop on any unhandled exception. This is to avoid memory leaks caused by crashed connections that will never progress, and callbacks that will never be called.
If you would like to keep the event loop alive, and you are sure you can clean up from unhandled exceptions sufficiently, you can use LSpace to add your own exception handler. If you do this then you should either call Bugsnag.notify
yourself, or re-raise the exception to ensure that the exception reaches Bugsnag.
LSpace.rescue do |e|
raise unless LSpace[:current_connection]
puts "Exception in #{LSpace[:session_id]}"
puts e
Bugsnag.notify e
cleanup_connection LSpace[:current_connection]
end
Further details
For further information about the Bugsnag ruby notifier, please see its README
Reporting Bugs or Feature Requests
Please report any bugs or feature requests on the github issues page for this project here:
https://github.com/bugsnag/bugsnag-em/issues
Contributing
- Fork the notifier on github
- Commit and push until you are happy with your contribution
- Run the tests with
rake spec
and make sure they all pass - Make a pull request
- Thanks!
Build Status
License
The Bugsnag EventMachine notifier is free software released under the MIT License. See LICENSE.TXT for details.