I noticed that in some scenarios I was seeing exceptions in a rails app in my local development environment triggering events being sent to the server. I first noticed this with a DelayedJob runner, but I am also able to repro this in a pry rails console:
$ rails c
** [Raven] Raven 0.6.0 ready to catch errors
Loading development environment (Rails 3.2.14)
[1] pry(main)> Raven.configuration.current_environment
=> "default"
[2] pry(main)> Raven.configuration.send_in_current_environment?
=> true
[3] pry(main)> Rails.env
=> "development"
I was able to workaround this by adding a line like this to the raven initializer:
require 'raven'
Raven.configure do |config|
# other stuff
# Workaround a bug where this was being set to "default" instead of "development" in some scenarios.
config.current_environment = Rails.env
end
I'm fine with the workaround, but I thought I would report this so it can hopefully be fixed in an upcoming version or help people who stumble across the same thing.
Have same problem with 0.6.0 version on rails 4 :+1: for fixing this.
rails c
I, [2013-12-04T11:52:21.645431 #9266] INFO -- : ** [Raven] Raven 0.7.1 ready to catch errors
Loading development environment (Rails 4.0.1)
[1] pry(main)> Raven.configuration.current_environment
=> "default"
[2] pry(main)> Raven.configuration.send_in_current_environment?
=> true
[3] pry(main)>
seems that 0.7.1 also could be affected, @phiggins thx for your workaround
I might also suggest that you add some documentation in your README that indicates test,cucumber and development do not send exceptions by default. The documentation does not mention that.
As of 0.10.0 we've now changed the feature to suggest that you unset SENTRY_DSN in non-production environments. The only behavior is still supported but it is now opt-in rather than opt-out.
This is explicitly because of how confusing this can be to users when they're testing it out and it doesn't send events.
f98c8fd07495ad086a4c5437ccdad362dcbf40a0 for reference
In case anyone else stumbles here like I did, the way to do this is by defining the environments you wish to use Raven with.
Per the docs:
Raven.configure do |config|
config.dsn = 'https://<key>:<secret>@app.getsentry.com/<project>'
config.environments = ['staging', 'production']
end
@dwickwire or, just use the SENTRY_DSN environment variable. If SENTRY_DSN is not set, Sentry won't start.
If you're using config.dsn, you _must_ use config.environments too, though.
I strongly recommend that this is added to the documentation on the readme--especially since most people copy+pasta that.
@chevinbrown https://github.com/getsentry/raven-ruby/blob/master/README.md#raven-only-runs-when-sentry_dsn-is-set
I get it, it just doesn't seem conventional compared to how other reporting gems work. Just my 2 cents.
@nateberkopec having the code below still will trigger sending an error to Sentry even if env var is a blank value.
Raven.configure do |config|
config.dsn = ENV['SENTRY_DSN']
end
The only way to fix it is addding:
config.environments = %w(staging production)
It makes sense to add that to the documentation. thanks!
FWIW, this is not currently on the rails docs page: https://docs.sentry.io/clients/ruby/integrations/rails/
Most helpful comment
In case anyone else stumbles here like I did, the way to do this is by defining the environments you wish to use Raven with.
Per the docs: