How prevent rollbar from reporting errors in the development environment?
Asked Answered
R

7

29

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.

Rrhoea answered 29/10, 2013 at 11:42 Comment(1)
Note 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.Lorenlorena
R
53

Put this code into initializers/rollbar.rb:

Rollbar.configure do |config|
  # ...

  unless Rails.env.production?
    config.enabled = false
  end

  # ...
end
Rrhoea answered 30/10, 2013 at 6:47 Comment(4)
FYI: not actual anymore. github.com/rollbar/rollbar-gem/blob/master/lib/generators/…Illimani
@FilipBartuzi The code you referenced only disables rollbar in test. The question asks to disable it in development.Gnathonic
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.Lorenzetti
@LukeGriffiths thansk, added it to answerRrhoea
A
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
Altorilievo answered 19/7, 2016 at 10:34 Comment(1)
I'm curious why this isn't the default setup. Who wants dev exceptions sent out?Lorenlorena
H
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
Hopkins answered 1/8, 2017 at 15:2 Comment(0)
M
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

Mastoiditis answered 11/3, 2016 at 17:10 Comment(0)
L
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
Lorenzetti answered 21/3, 2017 at 19:20 Comment(0)
C
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
Corinnacorinne answered 5/2, 2018 at 23:7 Comment(0)
C
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
Clatter answered 6/2, 2018 at 16:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.