Skip to content

Commit 0d0727f

Browse files
committed
Only report LocationPositionUpdater::NoResults in production
In our non-production environments we often have locations that are generated from fake data which means they're almost certainly going to fail. These aren't actionable errors so there's no need to send them to Sentry. Jira-Issue: MAV-6707 Jira-Issue: MAV-6379
1 parent 8e92a0b commit 0d0727f

7 files changed

Lines changed: 50 additions & 9 deletions

File tree

app/jobs/location_position_updater_job.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ def perform(location_id)
99
location = Location.find(location_id)
1010
LocationPositionUpdater.call(location)
1111
rescue LocationPositionUpdater::NoResults => e
12-
Sentry.capture_exception(e, level: "warning")
12+
if Settings.location_position_updater_job.capture_exception
13+
Sentry.capture_exception(e, level: "warning")
14+
else
15+
Rails.logger.warn(
16+
"Could not fetch position for: #{location.name} (#{location.id})"
17+
)
18+
Rails.logger.warn(e.backtrace.join("\n"))
19+
end
1320
end
1421
end

config/settings.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ ordnance_survey:
6464
api_key: <%= Rails.application.credentials.ordnance_survey&.api_key %>
6565
secret_key: <%= Rails.application.credentials.ordnance_survey&.secret_key %>
6666

67+
location_position_updater_job:
68+
capture_exception: true
69+
6770
# Set a value to override the default values set in config/initializers/devise.rb
6871
devise:
6972
timeout_in_seconds:

config/settings/development.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ reporting_api:
2929

3030
careplus:
3131
base_url: http://localhost:8080
32+
33+
location_position_updater_job:
34+
capture_exception: false

config/settings/end_to_end.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ splunk:
2626
reporting_api:
2727
client_app:
2828
root_url: http://localhost:4101
29+
30+
location_position_updater_job:
31+
capture_exception: false

config/settings/staging.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ pds:
2020

2121
careplus:
2222
base_url: <%= ENV.fetch("MOCK_CAREPLUS_URL", nil) %>
23+
24+
location_position_updater_job:
25+
capture_exception: false

config/settings/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ reporting_api:
2727

2828
careplus:
2929
base_url: http://localhost:8080
30+
31+
location_position_updater_job:
32+
capture_exception: false

spec/jobs/location_position_updater_job_spec.rb

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,35 @@
3939
allow(LocationPositionUpdater).to receive(:call).and_raise(error)
4040
end
4141

42-
it "captures the exception in Sentry at warning level" do
43-
expect(Sentry).to receive(:capture_exception).with(
44-
error,
45-
level: "warning"
46-
)
47-
perform
42+
context "when not capturing the exception" do
43+
it "doesn't capture the exception in Sentry" do
44+
expect(Sentry).not_to receive(:capture_exception)
45+
perform
46+
end
47+
48+
it "does not raise the error" do
49+
expect { perform }.not_to raise_error
50+
end
4851
end
4952

50-
it "does not raise the error" do
51-
expect { perform }.not_to raise_error
53+
context "when capturing the exception" do
54+
before do
55+
Settings.location_position_updater_job.capture_exception = true
56+
end
57+
58+
after { Settings.reload! }
59+
60+
it "captures the exception in Sentry at warning level" do
61+
expect(Sentry).to receive(:capture_exception).with(
62+
error,
63+
level: "warning"
64+
)
65+
perform
66+
end
67+
68+
it "does not raise the error" do
69+
expect { perform }.not_to raise_error
70+
end
5271
end
5372
end
5473

0 commit comments

Comments
 (0)