Skip to content

Commit 4ef2ef9

Browse files
committed
Rename to :should_report_error_callback
1 parent faa60b2 commit 4ef2ef9

5 files changed

Lines changed: 66 additions & 66 deletions

File tree

lib/sentry/config.ex

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,22 @@ defmodule Sentry.Config do
7878
with `oban_tags.` and with a value of `true`. *Available since 12.0.0*.
7979
"""
8080
],
81-
skip_error_report_callback: [
81+
should_report_error_callback: [
8282
type: {:or, [nil, {:fun, 2}]},
8383
default: nil,
8484
type_doc: "`(Oban.Worker.t() | nil, Oban.Job.t() -> boolean())` or `nil`",
8585
doc: """
86-
A function that determines whether to skip reporting errors for Oban job retries.
86+
A function that determines whether to report errors for Oban jobs.
8787
The function receives the worker module and the `Oban.Job` struct and should return
88-
`true` to skip reporting or `false` to report the error.
88+
`true` to report the error or `false` to skip reporting.
8989
9090
```elixir
91-
skip_error_report_callback: fn _worker, job ->
92-
job.attempt < job.max_attempts
91+
should_report_error_callback: fn _worker, job ->
92+
job.attempt >= job.max_attempts
9393
end
9494
```
9595
96-
This example skips reporting errors for all non-final retry attempts.
96+
This example only reports errors on final retry attempts.
9797
*Available since 12.0.0*.
9898
"""
9999
],
@@ -1097,14 +1097,14 @@ defmodule Sentry.Config do
10971097
"expected :oban_tags_to_sentry_tags to be nil, a function with arity 1, or a {module, function} tuple, got: #{inspect(other)}"}
10981098
end
10991099

1100-
def __validate_skip_error_report_callback__(nil), do: {:ok, nil}
1100+
def __validate_should_report_error_callback__(nil), do: {:ok, nil}
11011101

1102-
def __validate_skip_error_report_callback__(fun) when is_function(fun, 2) do
1102+
def __validate_should_report_error_callback__(fun) when is_function(fun, 2) do
11031103
{:ok, fun}
11041104
end
11051105

1106-
def __validate_skip_error_report_callback__(other) do
1106+
def __validate_should_report_error_callback__(other) do
11071107
{:error,
1108-
"expected :skip_error_report_callback to be nil or a function with arity 2, got: #{inspect(other)}"}
1108+
"expected :should_report_error_callback to be nil or a function with arity 2, got: #{inspect(other)}"}
11091109
end
11101110
end

lib/sentry/integrations/oban/error_reporter.ex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ defmodule Sentry.Integrations.Oban.ErrorReporter do
3939
end
4040

4141
defp should_report?(job, config) do
42-
case Keyword.get(config, :skip_error_report_callback) do
42+
case Keyword.get(config, :should_report_error_callback) do
4343
callback when is_function(callback, 2) ->
44-
not call_skip_error_report_callback(callback, job)
44+
call_should_report_error_callback(callback, job)
4545

4646
_ ->
4747
true
4848
end
4949
end
5050

51-
defp call_skip_error_report_callback(callback, job) do
51+
defp call_should_report_error_callback(callback, job) do
5252
worker =
5353
case apply(Oban.Worker, :from_string, [job.worker]) do
5454
{:ok, mod} ->
@@ -68,14 +68,14 @@ defmodule Sentry.Integrations.Oban.ErrorReporter do
6868
error ->
6969
Logger.warning(
7070
"""
71-
:skip_error_report_callback failed for worker #{inspect(worker)} \
71+
:should_report_error_callback failed for worker #{inspect(worker)} \
7272
(job ID #{job.id}):
73-
73+
7474
#{Exception.format(:error, error, __STACKTRACE__)}\
7575
"""
7676
)
7777

78-
false
78+
true
7979
end
8080
end
8181

test/sentry/config_oban_tags_to_sentry_tags_test.exs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,37 +60,37 @@ defmodule Sentry.ConfigObanTagsToSentryTagsTest do
6060
end
6161
end
6262

63-
describe "skip_error_report_callback configuration validation" do
63+
describe "should_report_error_callback configuration validation" do
6464
test "accepts nil" do
65-
assert :ok = put_test_config(integrations: [oban: [skip_error_report_callback: nil]])
66-
assert Sentry.Config.integrations()[:oban][:skip_error_report_callback] == nil
65+
assert :ok = put_test_config(integrations: [oban: [should_report_error_callback: nil]])
66+
assert Sentry.Config.integrations()[:oban][:should_report_error_callback] == nil
6767
end
6868

6969
test "accepts function with arity 2" do
7070
fun = fn _worker, _job -> true end
71-
assert :ok = put_test_config(integrations: [oban: [skip_error_report_callback: fun]])
72-
assert Sentry.Config.integrations()[:oban][:skip_error_report_callback] == fun
71+
assert :ok = put_test_config(integrations: [oban: [should_report_error_callback: fun]])
72+
assert Sentry.Config.integrations()[:oban][:should_report_error_callback] == fun
7373
end
7474

7575
test "rejects function with wrong arity" do
7676
fun = fn _job -> true end
7777

78-
assert_raise ArgumentError, ~r/expected :skip_error_report_callback to be/, fn ->
79-
put_test_config(integrations: [oban: [skip_error_report_callback: fun]])
78+
assert_raise ArgumentError, ~r/invalid value for :should_report_error_callback/, fn ->
79+
put_test_config(integrations: [oban: [should_report_error_callback: fun]])
8080
end
8181
end
8282

8383
test "rejects invalid types" do
84-
assert_raise ArgumentError, ~r/expected :skip_error_report_callback to be/, fn ->
85-
put_test_config(integrations: [oban: [skip_error_report_callback: "invalid"]])
84+
assert_raise ArgumentError, ~r/invalid value for :should_report_error_callback/, fn ->
85+
put_test_config(integrations: [oban: [should_report_error_callback: "invalid"]])
8686
end
8787

88-
assert_raise ArgumentError, ~r/expected :skip_error_report_callback to be/, fn ->
89-
put_test_config(integrations: [oban: [skip_error_report_callback: 123]])
88+
assert_raise ArgumentError, ~r/invalid value for :should_report_error_callback/, fn ->
89+
put_test_config(integrations: [oban: [should_report_error_callback: 123]])
9090
end
9191

92-
assert_raise ArgumentError, ~r/expected :skip_error_report_callback to be/, fn ->
93-
put_test_config(integrations: [oban: [skip_error_report_callback: []]])
92+
assert_raise ArgumentError, ~r/invalid value for :should_report_error_callback/, fn ->
93+
put_test_config(integrations: [oban: [should_report_error_callback: []]])
9494
end
9595
end
9696
end

test/sentry/integrations/oban/error_reporter_test.exs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ defmodule Sentry.Integrations.Oban.ErrorReporterTest do
213213
assert event.tags.custom_tag == "custom_value"
214214
end
215215

216-
test "skip_error_report_callback skips when callback returns true" do
216+
test "should_report_error_callback skips when callback returns false" do
217217
job =
218218
%{"id" => "123", "entity" => "user", "type" => "delete"}
219219
|> MyWorker.new()
@@ -225,34 +225,34 @@ defmodule Sentry.Integrations.Oban.ErrorReporterTest do
225225

226226
job_attempt_1 = Map.merge(job, %{attempt: 1, max_attempts: 3})
227227

228-
# Callback returns true -> skip reporting
228+
# Callback returns false -> skip reporting
229229
assert :ok =
230230
ErrorReporter.handle_event(
231231
[:oban, :job, :exception],
232232
%{},
233233
%{job: job_attempt_1, kind: :error, reason: reason, stacktrace: []},
234-
skip_error_report_callback: fn _worker, job -> job.attempt < job.max_attempts end
234+
should_report_error_callback: fn _worker, job -> job.attempt >= job.max_attempts end
235235
)
236236

237237
assert [] = Sentry.Test.pop_sentry_reports()
238238

239-
# Final attempt: callback returns false -> report
239+
# Final attempt: callback returns true -> report
240240
job_attempt_3 = Map.merge(job, %{attempt: 3, max_attempts: 3})
241241

242242
assert :ok =
243243
ErrorReporter.handle_event(
244244
[:oban, :job, :exception],
245245
%{},
246246
%{job: job_attempt_3, kind: :error, reason: reason, stacktrace: []},
247-
skip_error_report_callback: fn _worker, job -> job.attempt < job.max_attempts end
247+
should_report_error_callback: fn _worker, job -> job.attempt >= job.max_attempts end
248248
)
249249

250250
assert [event] = Sentry.Test.pop_sentry_reports()
251251
assert event.original_exception == %RuntimeError{message: "oops"}
252252
assert event.tags.oban_worker == "Sentry.Integrations.Oban.ErrorReporterTest.MyWorker"
253253
end
254254

255-
test "skip_error_report_callback receives worker module and job" do
255+
test "should_report_error_callback receives worker module and job" do
256256
job =
257257
%{"id" => "123", "entity" => "user", "type" => "delete"}
258258
|> MyWorker.new()
@@ -268,9 +268,9 @@ defmodule Sentry.Integrations.Oban.ErrorReporterTest do
268268
[:oban, :job, :exception],
269269
%{},
270270
%{job: job, kind: :error, reason: reason, stacktrace: []},
271-
skip_error_report_callback: fn worker, received_job ->
271+
should_report_error_callback: fn worker, received_job ->
272272
send(test_pid, {:callback_args, worker, received_job})
273-
false
273+
true
274274
end
275275
)
276276

@@ -279,28 +279,28 @@ defmodule Sentry.Integrations.Oban.ErrorReporterTest do
279279
assert received_job == job
280280
end
281281

282-
test "skip_error_report_callback reports when callback returns false" do
282+
test "should_report_error_callback reports when callback returns true" do
283283
Sentry.Test.start_collecting()
284284

285285
emit_telemetry_for_failed_job(:error, %RuntimeError{message: "oops"}, [],
286-
skip_error_report_callback: fn _worker, _job -> false end
286+
should_report_error_callback: fn _worker, _job -> true end
287287
)
288288

289289
assert [event] = Sentry.Test.pop_sentry_reports()
290290
assert event.original_exception == %RuntimeError{message: "oops"}
291291
end
292292

293-
test "skip_error_report_callback handles errors gracefully and defaults to reporting" do
293+
test "should_report_error_callback handles errors gracefully and defaults to reporting" do
294294
Sentry.Test.start_collecting()
295295

296296
log =
297297
capture_log(fn ->
298298
emit_telemetry_for_failed_job(:error, %RuntimeError{message: "oops"}, [],
299-
skip_error_report_callback: fn _worker, _job -> raise "callback error" end
299+
should_report_error_callback: fn _worker, _job -> raise "callback error" end
300300
)
301301
end)
302302

303-
assert log =~ "skip_error_report_callback failed"
303+
assert log =~ "should_report_error_callback failed"
304304
assert log =~ "Sentry.Integrations.Oban.ErrorReporterTest.MyWorker"
305305
assert log =~ "callback error"
306306

test_integrations/phoenix_app/test/phoenix_app/oban_test.exs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ defmodule Sentry.Integrations.Phoenix.ObanTest do
5757
assert [] = transaction.spans
5858
end
5959

60-
describe "skip_error_report_callback config" do
60+
describe "should_report_error_callback config" do
6161
setup do
6262
:telemetry.detach(ErrorReporter)
6363

@@ -69,13 +69,13 @@ defmodule Sentry.Integrations.Phoenix.ObanTest do
6969
:ok
7070
end
7171

72-
test "skips error reporting when callback returns true" do
72+
test "skips error reporting when callback returns false" do
7373
test_pid = self()
7474

7575
ErrorReporter.attach(
76-
skip_error_report_callback: fn worker, job ->
76+
should_report_error_callback: fn worker, job ->
7777
send(test_pid, {:callback_invoked, worker, job})
78-
true
78+
false
7979
end
8080
)
8181

@@ -94,13 +94,13 @@ defmodule Sentry.Integrations.Phoenix.ObanTest do
9494
assert [] = Sentry.Test.pop_sentry_reports()
9595
end
9696

97-
test "reports error when callback returns false" do
97+
test "reports error when callback returns true" do
9898
test_pid = self()
9999

100100
ErrorReporter.attach(
101-
skip_error_report_callback: fn worker, job ->
101+
should_report_error_callback: fn worker, job ->
102102
send(test_pid, {:callback_invoked, worker, job})
103-
false
103+
true
104104
end
105105
)
106106

@@ -124,9 +124,9 @@ defmodule Sentry.Integrations.Phoenix.ObanTest do
124124
test_pid = self()
125125

126126
ErrorReporter.attach(
127-
skip_error_report_callback: fn worker, job ->
127+
should_report_error_callback: fn worker, job ->
128128
send(test_pid, {:callback_args, worker, job})
129-
false
129+
true
130130
end
131131
)
132132

@@ -155,10 +155,10 @@ defmodule Sentry.Integrations.Phoenix.ObanTest do
155155
test_pid = self()
156156

157157
ErrorReporter.attach(
158-
skip_error_report_callback: fn _worker, job ->
159-
should_skip = job.attempt < job.max_attempts
160-
send(test_pid, {:skip_decision, job.attempt, job.max_attempts, should_skip})
161-
should_skip
158+
should_report_error_callback: fn _worker, job ->
159+
should_report = job.attempt >= job.max_attempts
160+
send(test_pid, {:report_decision, job.attempt, job.max_attempts, should_report})
161+
should_report
162162
end
163163
)
164164

@@ -169,10 +169,10 @@ defmodule Sentry.Integrations.Phoenix.ObanTest do
169169

170170
Oban.drain_queue(queue: :default)
171171

172-
assert_receive {:skip_decision, attempt, max_attempts, should_skip}
172+
assert_receive {:report_decision, attempt, max_attempts, should_report}
173173
assert attempt == 1
174174
assert max_attempts == 3
175-
assert should_skip == true
175+
assert should_report == false
176176

177177
assert [] = Sentry.Test.pop_sentry_reports()
178178
end
@@ -181,7 +181,7 @@ defmodule Sentry.Integrations.Phoenix.ObanTest do
181181
log =
182182
capture_log(fn ->
183183
ErrorReporter.attach(
184-
skip_error_report_callback: fn _worker, _job ->
184+
should_report_error_callback: fn _worker, _job ->
185185
raise "callback crashed!"
186186
end
187187
)
@@ -194,7 +194,7 @@ defmodule Sentry.Integrations.Phoenix.ObanTest do
194194
Oban.drain_queue(queue: :default)
195195
end)
196196

197-
assert log =~ "skip_error_report_callback failed"
197+
assert log =~ "should_report_error_callback failed"
198198
assert log =~ "FailingWorker"
199199
assert log =~ "callback crashed!"
200200

@@ -220,10 +220,10 @@ defmodule Sentry.Integrations.Phoenix.ObanTest do
220220
test_pid = self()
221221

222222
ErrorReporter.attach(
223-
skip_error_report_callback: fn worker, _job ->
224-
should_skip = worker == FailingWorker
225-
send(test_pid, {:worker_check, worker, should_skip})
226-
should_skip
223+
should_report_error_callback: fn worker, _job ->
224+
should_report = worker != FailingWorker
225+
send(test_pid, {:worker_check, worker, should_report})
226+
should_report
227227
end
228228
)
229229

@@ -234,7 +234,7 @@ defmodule Sentry.Integrations.Phoenix.ObanTest do
234234

235235
Oban.drain_queue(queue: :default)
236236

237-
assert_receive {:worker_check, FailingWorker, true}
237+
assert_receive {:worker_check, FailingWorker, false}
238238

239239
assert [] = Sentry.Test.pop_sentry_reports()
240240
end
@@ -245,9 +245,9 @@ defmodule Sentry.Integrations.Phoenix.ObanTest do
245245
log =
246246
capture_log(fn ->
247247
ErrorReporter.attach(
248-
skip_error_report_callback: fn worker, job ->
248+
should_report_error_callback: fn worker, job ->
249249
send(test_pid, {:callback_with_unknown_worker, worker, job})
250-
false
250+
true
251251
end
252252
)
253253

0 commit comments

Comments
 (0)