Rails secret problem when Sentry.io integration exists

Hello,

After I set up the sentry.io integration in my rails 5.2 app the following command: rails secret returns:

I, [2018-11-23T21:50:38.855829 #25462] INFO – sentry: ** [Raven] Raven 2.7.4 ready to catch errors
450027042d9d4ff15b798b23f8a85a1cf62b2b5740906421d8613e01e2401b1dffxxxxxxxx

so it is not correct

The informational message of sentry is very nice and I want it but in this case there is a problem…

How can I run rails and somehow instruct sentry to not produce the informational message?
I could also some how disable sentry for this specific run of rails (it could be with a env variable)

Please advise

To disable it you can simply set SENTRY_DSN to a falsey value

$ rails secret
I, [2018-11-27T05:06:42.828454 #21343] INFO – sentry: ** [Raven] Raven 2.7.4 ready to catch errors
xxxxxxxxxxxxxxxxxxxxxx

$ SENTRY_DSN=falsery rails secret
I, [2018-11-27T05:07:15.925727 #21383] INFO – sentry: ** [Raven] Raven 2.7.4 ready to catch errors
xxxxxxxxxxxxxxxxxxxxxxxx

SENTRY_DSN= rails secret

The same:

$ rails secret
I, [2018-11-28T08:25:46.621725 #7561]  INFO -- sentry: ** [Raven] Raven 2.7.4 ready to catch errors
xxxxxxxx
$ SENTRY_DSN= rails secret
I, [2018-11-28T08:25:55.804088 #7591]  INFO -- sentry: ** [Raven] Raven 2.7.4 ready to catch errors
xxxx

To be clear you need to set it to an empty value in whatever way you configure the DSN. I dont know how you do this, as its implementation specific, but if you were using an environment variable (like Heroku does), then that’s how you’d clear it there.

OK I see…

I am using an yml config file for my env variables…

I need it because I use this:

eb setenv SECRET_KEY_BASE=$(A_SENTRY_DISABLE=any rails secret)

I want to disable it only for generating the secret and not all the time…

I am using this (temporary) approach:

Gemfile:

unless ENV.has_key?('A_SENTRY_DISABLE')     # temp fix with rails secret
  gem "sentry-raven"
end

config/application.rb

unless ENV.has_key?('A_SENTRY_DISABLE')     # temp fix with rails secret
  Raven.configure do |config|
    config.dsn = ENV['A_SENTRY_URL']
  end
end

app/controllers/application_controller.rb

class ApplicationController < ActionController::Base
  before_action :set_raven_context

  private

  def set_raven_context
    unless ENV.has_key?('A_SENTRY_DISABLE')     # temp fix with rails secret
      Raven.user_context(id: session[:current_user_id]) # or anything else in session
      Raven.extra_context(params: params.to_unsafe_h, url: request.url)
    end
  end
end

Anyway, thank you for your kind help and support :slight_smile: