From 8ff6832b4d989d6145222af9cc7e289c105fa39c Mon Sep 17 00:00:00 2001 From: "Ben Sheldon [he/him]" Date: Tue, 30 Jul 2024 16:36:08 -0700 Subject: [PATCH] Replace sentry-raven with sentry-rails --- Gemfile | 2 +- Gemfile.lock | 10 +++++--- app/jobs/fetch_service_list_job.rb | 2 +- app/jobs/fetch_service_requests_job.rb | 2 +- .../fetch_service_requests_recursively_job.rb | 2 +- config/initializers/sentry.rb | 23 ++++++++++++++----- 6 files changed, 28 insertions(+), 13 deletions(-) diff --git a/Gemfile b/Gemfile index 63f01cd..5a81f09 100644 --- a/Gemfile +++ b/Gemfile @@ -38,7 +38,7 @@ gem 'rack-host-redirect' gem 'rails', '~> 7.1' gem 'sass-rails' gem 'scenic' -gem 'sentry-raven' +gem 'sentry-rails' gem 'slim' gem 'slim-rails' gem 'terser' diff --git a/Gemfile.lock b/Gemfile.lock index cc1c699..12b2073 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -441,8 +441,12 @@ GEM rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) - sentry-raven (2.13.0) - faraday (>= 0.7.6, < 1.0) + sentry-rails (5.18.2) + railties (>= 5.0) + sentry-ruby (~> 5.18.2) + sentry-ruby (5.18.2) + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) slim (5.2.1) temple (~> 0.10.0) tilt (>= 2.1.0) @@ -549,7 +553,7 @@ DEPENDENCIES sass-rails scenic selenium-webdriver - sentry-raven + sentry-rails slim slim-rails slim_lint diff --git a/app/jobs/fetch_service_list_job.rb b/app/jobs/fetch_service_list_job.rb index 3fcecd6..7e5b9e7 100644 --- a/app/jobs/fetch_service_list_job.rb +++ b/app/jobs/fetch_service_list_job.rb @@ -2,7 +2,7 @@ class FetchServiceListJob < ApplicationJob def perform(city) - Raven.extra_context(city: city.slug) + Sentry.set_context(:city, { slug: city.slug }) Rails.logger.info "Collecting service definitions list from #{city.name}" api = City::Api.new city new_service_list = api.fetch_service_list diff --git a/app/jobs/fetch_service_requests_job.rb b/app/jobs/fetch_service_requests_job.rb index f85e9d7..84e6fad 100644 --- a/app/jobs/fetch_service_requests_job.rb +++ b/app/jobs/fetch_service_requests_job.rb @@ -2,7 +2,7 @@ class FetchServiceRequestsJob < ApplicationJob def perform(city) - Raven.extra_context(city: city.slug) + Sentry.set_context(:city, { slug: city.slug }) Rails.logger.info "Collecting service requests from #{city.name}" api = City::Api.new city new_service_requests = api.fetch_service_requests diff --git a/app/jobs/fetch_service_requests_recursively_job.rb b/app/jobs/fetch_service_requests_recursively_job.rb index abdafab..21e411f 100644 --- a/app/jobs/fetch_service_requests_recursively_job.rb +++ b/app/jobs/fetch_service_requests_recursively_job.rb @@ -9,7 +9,7 @@ def perform(city, start_at = 7.days.ago, end_at = Time.current, interval = INITI interval = interval.positive? ? interval.second : 1.second api_limit = city.requests_limit || 50 - Raven.extra_context(city: city.slug) + Sentry.set_context(:city, { slug: city.slug }) start_date = start_at.to_datetime end_date = end_at.to_datetime diff --git a/config/initializers/sentry.rb b/config/initializers/sentry.rb index 449d0f6..b896120 100644 --- a/config/initializers/sentry.rb +++ b/config/initializers/sentry.rb @@ -1,7 +1,18 @@ -Raven.configure do |config| - config.environments = %w[ production ] -end +# frozen_string_literal: true + +if defined? Sentry + Sentry.init do |config| + config.enabled_environments = %w[production staging] + config.excluded_exceptions = Sentry::Configuration::IGNORE_DEFAULT + Sentry::Rails::IGNORE_DEFAULT + %w[ + ActionController::UnknownFormat + Rack::Timeout::RequestTimeoutError + Rack::Timeout::RequestExpiryError + ] -Raven.tags_context({ - 'environment' => Rails.env -}) + # use Rails' parameter filter to sanitize the event + filter = ActiveSupport::ParameterFilter.new(Rails.application.config.filter_parameters - [:name, :filename]) + config.before_send = lambda do |event, _hint| + filter.filter(event.to_hash) + end + end +end