How I can disable the rollbar gem from reporting errors in my development environment? I want to get errors only from staging and production, but I didn't find it in docs on Rollbar's site.
Asked
Active
Viewed 1.1k times
29
-
2Note that if you disable Rollbar in development with one of the techniques below, then `rake rollbar:test` won't work. You need to enable production mode. – mpoisot Nov 11 '16 at 21:24
7 Answers
53
Put this code into initializers/rollbar.rb:
Rollbar.configure do |config|
# ...
unless Rails.env.production?
config.enabled = false
end
# ...
end

piton4eg
- 1,096
- 2
- 10
- 21
-
2FYI: not actual anymore. https://github.com/rollbar/rollbar-gem/blob/master/lib/generators/rollbar/templates/initializer.rb#L16-L19 – Filip Bartuzi Sep 11 '15 at 17:52
-
1@FilipBartuzi The code you referenced only disables rollbar in test. The question asks to disable it in development. – MustModify Sep 20 '15 at 21:25
-
I don't have sufficient rights to do this but it would be more clear if the above code sample were edited to reflect the full namespace environment where the code should run. Recommend to prepend line: `Rollbar.configure do |config|` and then append the corresponding `end` to the code sample. Conceivably someone's initializer could be empty or absent and rollbar would still function. – Luke Griffiths Mar 21 '17 at 19:12
-
13
I changed the following in config/initializers/rollbar.rb:
# Here we'll disable in 'test':
if Rails.env.test?
config.enabled = false
end
to
# Here we'll disable in 'test' and 'development':
if Rails.env.test? || Rails.env.development?
config.enabled = false
end

iheggie
- 2,011
- 23
- 23
-
3I'm curious why this isn't the default setup. Who wants dev exceptions sent out? – mpoisot Nov 11 '16 at 21:22
11
Don't use an if
(or unless
) statement just to set a boolean. Also, you probably want Rollbar enabled in staging in case you need it.
Rollbar.configure do |config|
config.enabled = Rails.env.production? || Rails.env.staging?
end

ulysses_rex
- 330
- 3
- 16

Tim Scott
- 15,106
- 9
- 65
- 79
2
I believe the following better answers the question:
if Rails.env.development?
config.enabled = false
end
This code should be written in config/initializers/rollbar.rb

robskrob
- 2,720
- 4
- 31
- 58
2
The other answers are correct so I am just adding this to reduce confusion about exactly what code is required:
Ensure the following is in config/initializers/rollbar.rb:
Rollbar.configure do |config|
# ...
unless Rails.env.production?
config.enabled = false
end
# ...
end

Luke Griffiths
- 859
- 8
- 16
2
I only want Rollbar to report issues in production, so I've done this:
Rollbar.configure do |config|
# ...
config.enabled = Rails.env.production?
# ...
end

Turgs
- 1,729
- 1
- 20
- 49
1
I use this in my rollbar config.
config/initializers/rollbar.rb
Rollbar.configure do |config|
# ...
if Rails.env.in? %w[test development]
config.enabled = false
end
# ...
end

zhisme
- 2,368
- 2
- 19
- 28