Migrate sentry-raven to sentry-ruby gem in rails

by Juan Vásquez, 01 Jul 2022
daily, rails

To be honest, following the sentry documentation was pretty straightforward.

Change gems

# Old
gem "sentry-raven"
# New
gem "sentry-ruby"
gem "sentry-rails"

Change initialization

Raven.configure do |config|
  config.dsn = "DSN"
end
# New
Sentry.init do |config|
  config.dsn = "DSN"
end

Change Raven to Sentry

# Old
Raven.capture_message("test", extra: { debug: true })
# New
Sentry.capture_message("test", extra: { debug: true })

Extra

The only thing I had to check was related to a key called sanitize_fields that was removed in this new SDK (sentry-ruby) but they implemented at least three new options:

  • Use the new key called send_default_pii = true already filter the params.
  • Use a filtering method in the initialization config.
Copied

Sentry.init do |config|
  #...

  # this example uses Rails' parameter filter to sanitize the event payload
  # for Rails 6+
  filter = ActiveSupport::ParameterFilter.new(Rails.application.config.filter_parameters)
  # for Rails 5
  filter = ActionDispatch::Http::ParameterFilter.new(Rails.application.config.filter_parameters)
  config.before_send = lambda do |event, hint|
    filter.filter(event.to_hash)
  end
end

Feel free to pick one, we picked the second one.

more info about sanitize fields