Project

bugsnag-em

0.0
Repository is archived
No release in over 3 years
Low commit activity in last 3 years
Let's you rescue errors asynchronously while keeping track of context
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 0

Runtime

 Project Readme

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

  1. Add the bugsnag-em gem to your Gemfile

    gem "bugsnag-em"
    gem "bugsnag", "~> 5.0" # bugsnag-em is not compatible with bugsnag-ruby v6
  2. Install the gem

    bundle install
  3. 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

Build Status

Build Status

License

The Bugsnag EventMachine notifier is free software released under the MIT License. See LICENSE.TXT for details.