MindscapeHQ / raygun4ruby

The Ruby & Ruby on Rails provider for Raygun
https://raygun.com
MIT License
38 stars 40 forks source link

Sinatra instructions/clarify non-Rails instructions (and make Rack middleware?) #6

Closed henrik closed 7 years ago

henrik commented 11 years ago

I noticed Honeybadger have Rack middleware to make Sinatra integration really easy: https://github.com/honeybadger-io/honeybadger-sinatra-example/blob/master/server.rb

And they have that example repo to show how to use it.

Your instructions on non-Rails use don't mention the API token configuration, and having to wrap everything in a block in e.g. a Sinatra app is not ideal. I suggest adding Rack middleware with instructions. Or at least instructions for the current functionality geared specifically to Sinatra apps.

nikz commented 11 years ago

Hi Henrik,

Thanks for your suggestions, I've opened some Pull Requests that should address most of them (let me know if I've left something out).

I'm still working on some Sinatra documentation, but Raygun4Ruby is already using Rack middleware, so you should be able to just use Raygun::RackExceptionInterceptor in your Sinatra app?

Nik

henrik commented 11 years ago

Oh, cool, didn't notice that. Thanks, will try it out.

henrik commented 11 years ago

Trying it out. Maybe this pattern is useful for the docs (or would you recommend something else?):

raygun_api_key = ENV["RAYGUN_API_KEY"]

Raygun.setup do |config|
  config.api_key = raygun_api_key
  config.silence_reporting = !raygun_api_key
end

use Raygun::RackExceptionInterceptor
henrik commented 11 years ago

Oh, and for the middleware to work it seems your Sinatra app needs set :raise_errors, true.

henrik commented 11 years ago

Or this: https://github.com/honeybadger-io/honeybadger-ruby/pull/6

henrik commented 11 years ago

I ended up using this: https://github.com/henrik/etsy-rss/blob/master/raygun_rack.rb

nikz commented 11 years ago

Hey Henrik,

I've pushed an example here: https://github.com/MindscapeHQ/raygun4ruby/pull/13.

We're not using either of those env hash entries - so I'm not sure if they're necessary.

What do you think?

Nik

henrik commented 11 years ago

Assigning env["raygun.error_id"] is not necessary IIRC (just consistent with other Rack stuff), but getting the exception from something like env["rack.exception"] || env["sinatra.error"] most definitely is. Otherwise you won't get errors tracked with the default setting of set :raise_errors, false. I had some pain trying to figure out why no exceptions were tracked until I figured that one out.