Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Sentry #914

Draft
wants to merge 1 commit into
base: 2024-upgrades-main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Expand Up @@ -78,7 +78,7 @@ supporters_path=/civicrm/example-action-api
cors_allowed_domains=https://example.org https://some.example.com
fastly_api_key=

# Error reporting (not required)
# Error reporting (not required, leave empty to prevent sentry from sending events)
sentry_dsn=

# Miscellaneous (not required)
Expand Down
4 changes: 3 additions & 1 deletion Gemfile
Expand Up @@ -61,7 +61,9 @@ gem "daemons", "~> 1"
gem "delayed_job_active_record", "~> 4"

# Exception monitoring
gem "sentry-raven", "~> 0.15"
gem "sentry-ruby", "~> 5.17.2"
gem "sentry-rails", "~> 5.17.2"
gem "sentry-delayed_job", "~> 5.17.2"

# Fancy counter caches
gem "counter_culture", "~> 2.0"
Expand Down
22 changes: 13 additions & 9 deletions Gemfile.lock
Expand Up @@ -133,6 +133,7 @@ GEM
erubi (>= 1.0.0)
rack (>= 0.9.0)
rouge (>= 1.0.0)
bigdecimal (3.1.7)
bootstrap-daterangepicker-rails (3.0.4)
railties (>= 4.0)
bootstrap-sass (3.4.1)
Expand Down Expand Up @@ -202,11 +203,6 @@ GEM
factory_bot_rails (6.2.0)
factory_bot (~> 6.2.0)
railties (>= 5.0.0)
faraday (2.7.11)
base64
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-net_http (3.0.2)
fast_inserter (2.0.0)
activerecord (>= 4.1.0)
fastly (2.5.3)
Expand Down Expand Up @@ -414,7 +410,6 @@ GEM
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
safely_block (0.4.0)
sanitize (6.1.0)
Expand Down Expand Up @@ -442,8 +437,15 @@ GEM
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
sentry-raven (0.15.6)
faraday (>= 0.7.6)
sentry-delayed_job (5.17.2)
delayed_job (>= 4.0)
sentry-ruby (~> 5.17.2)
sentry-rails (5.17.2)
railties (>= 5.0)
sentry-ruby (~> 5.17.2)
sentry-ruby (5.17.2)
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
snaky_hash (2.0.1)
hashie
version_gem (~> 1.1, >= 1.1.1)
Expand Down Expand Up @@ -566,7 +568,9 @@ DEPENDENCIES
sdoc
select2-rails
selenium-devtools
sentry-raven (~> 0.15)
sentry-delayed_job (~> 5.17.2)
sentry-rails (~> 5.17.2)
sentry-ruby (~> 5.17.2)
uglifier (>= 1.3.0)
uuidtools (~> 2)
webmock (~> 3)
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/concerns/logged_invisible_captcha.rb
Expand Up @@ -12,7 +12,6 @@ def on_timestamp_spam(options = {})
end

def log_failure
Raven.capture_message("A suspected automated form fill was rejected",
level: :info)
Sentry.capture_message("A suspected automated form fill was rejected", level: :info)
end
end
13 changes: 6 additions & 7 deletions app/controllers/sns_controller.rb
Expand Up @@ -4,7 +4,7 @@
class SnsController < ApplicationController
protect_from_forgery with: :null_session
before_action :verify_amazon_authorize_key
before_action :set_context, :log_request
before_action :log_request

def bounce
message = set_message
Expand Down Expand Up @@ -33,18 +33,17 @@ def verify_amazon_authorize_key
raise ActiveRecord::RecordNotFound unless params["amazon_authorize_key"] == Rails.application.secrets.amazon_authorize_key
end

def set_context
Raven.extra_context(message: request.body.read)
request.body.rewind
end
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This moved to being called inside of the .with_scope block


def set_message
body = JSON.parse(request.body.read)
JSON.parse(body["Message"])
end

def log_request
logger.info "Received Amazon SES #{action_name} notification"
Raven.capture_message("Received Amazon SES #{action_name} notification", level: "info")
Sentry.with_scope do |scope|
scope.set_extras(message: request.body.read)
Sentry.capture_message("Received Amazon SES #{action_name} notification", level: "info")
end
request.body.rewind
end
end
2 changes: 1 addition & 1 deletion config/initializers/rack_attack_logger.rb
Expand Up @@ -5,5 +5,5 @@
ip = req.ip
end
message = "Rate limit exceeded on #{req.fullpath}"
Raven.capture_message(message, extra: { ip: ip })
Sentry.capture_message(message, extra: { ip: ip })
end
6 changes: 2 additions & 4 deletions config/initializers/sentry.rb
@@ -1,5 +1,3 @@
unless Rails.application.secrets.sentry_dsn.nil?
Raven.configure do |config|
config.dsn = Rails.application.secrets.sentry_dsn
end
Sentry.init do |config|
config.dsn = Rails.application.secrets.sentry_dsn
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to init in order not to error in tests. It won't send events if sentry_dsn is empty.

end
2 changes: 1 addition & 1 deletion lib/call_tool.rb
Expand Up @@ -54,7 +54,7 @@ def self.get(action, params = {})
if Rails.application.secrets.sentry_dsn.nil?
raise error
else
Raven.capture_message(error, level: "info")
Sentry.capture_message(error, level: "info")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/civicrm.rb
Expand Up @@ -97,7 +97,7 @@ def self.post(params)

res
rescue StandardError => e
Raven.capture_exception(e)
Sentry.capture_exception(e)
Rails.logger.error "#{e} (#{e.class})!"
false
end
Expand Down
4 changes: 2 additions & 2 deletions lib/congress_forms.rb
Expand Up @@ -122,7 +122,7 @@ def self.data_path(base_path, params = {}, bioguide_id = nil)
def self.get(path)
JSON.parse RestClient.get(base_url + path)
rescue RestClient::ExceptionWithResponse => e
Raven.capture_exception(e)
Sentry.capture_exception(e)
Rails.logger.error e
{}
end
Expand All @@ -131,7 +131,7 @@ def self.post(path, body = {})
JSON.parse RestClient.post(base_url + path, body.to_json,
{ content_type: :json, accept: :json })
rescue RestClient::ExceptionWithResponse => e
Raven.capture_exception(e)
Sentry.capture_exception(e)
Rails.logger.error e
raise RequestFailed
end
Expand Down
2 changes: 1 addition & 1 deletion lib/smarty_streets.rb
Expand Up @@ -32,7 +32,7 @@ class AddressNotFound < StandardError; end
def self.post(url, params)
JSON.parse RestClient.get("#{url}?#{params.to_query}")
rescue StandardError => e
Raven.capture_exception(e)
Sentry.capture_exception(e)
Rails.logger.error "#{e} (#{e.class})!"
false
end
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/concerns/logged_invisible_captcha_spec.rb
Expand Up @@ -13,7 +13,7 @@ def create; end
end

it "logs spammy requests to Sentry" do
expect(Raven).to receive(:capture_message)
expect(Sentry).to receive(:capture_message)
post :create, params: { foo: "bar" }
end
end
2 changes: 1 addition & 1 deletion spec/lib/call_tool_spec.rb
Expand Up @@ -70,7 +70,7 @@
expect(exception).to receive(:http_body) { %({"error": "13224: number invalid"}) }
expect(RestClient).to receive(:get).and_raise(exception)

expect(Raven).not_to receive(:capture_message)
expect(Sentry).not_to receive(:capture_message)
expect { CallTool.campaign_call(campaign, **keywords) }.not_to raise_exception
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/requests/sns_spec.rb
Expand Up @@ -3,6 +3,7 @@
RSpec.describe "Amazon SNS endpoints", type: :request do
before(:each) do
Rails.application.secrets.amazon_authorize_key = "my_amazon_key"
allow(Sentry).to receive(:capture_message)
end

describe "complaint notification" do
Expand All @@ -13,6 +14,7 @@
params: body, headers: headers
expect(JSON.parse(response.body)["success"]).to be true
expect(Complaint.count).to eq 1
expect(Sentry).to have_received(:capture_message)
end
end
end