rollbar/rollbar-gem — pull request #130 by jondeandres (2014-09-09 23:59:01+00:00)
Title: Add Sinatra middleware.

Hi!

I had some problems with the gem using it in a Sinatra project. I had to write my own middleware and I think it could be interesting for you having it in the gem.

The problem comes from here in the Sinatra code:
https://github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb#L1112
https://github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb#L1122

The first line raise the error only in development environment by default, and the second one only raise the error in test mode, https://github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb#L1839.

However Sinatra saves the exception in `env['sinatra.error']`, you can see it here:
https://github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb#L1098

The result of all of this is that the exception doesn't arrive to your monkey patch to `Rack::Builder` so it doesn't work for Sinatra projects.

IMHO it's better don't monkey patch `Rack::Builder` and just add the middleware to the rack stack using `use Rollbar::Middleware::Rack`, for example. But ok, this change could break the projects of other people so I've only added a isolated Sinatra middleware.

I think it could be interesting to add a warn message and a condition to monkey patch or not `Rack::Builder` and in next versions just add a middlware so the users can add it to their apps.

I hope this code is useful for you, it helped me in my developments.