@@ -4,14 +4,14 @@ defmodule Sentry.Integrations.Oban.ErrorReporter do
44 # See this blog post:
55 # https://getoban.pro/articles/enhancing-error-reporting
66
7- @ spec attach ( ) :: :ok
8- def attach do
7+ @ spec attach_telemetry_handler ( keyword ( ) ) :: :ok
8+ def attach_telemetry_handler ( config ) do
99 _ =
1010 :telemetry . attach (
1111 __MODULE__ ,
1212 [ :oban , :job , :exception ] ,
1313 & __MODULE__ . handle_event / 4 ,
14- :no_config
14+ config
1515 )
1616
1717 :ok
@@ -21,9 +21,24 @@ defmodule Sentry.Integrations.Oban.ErrorReporter do
2121 [ atom ( ) , ... ] ,
2222 term ( ) ,
2323 % { required ( :job ) => struct ( ) , optional ( term ( ) ) => term ( ) } ,
24- :no_config
24+ keyword ( )
2525 ) :: :ok
26- def handle_event ( [ :oban , :job , :exception ] , _measurements , % { job: job } = _metadata , :no_config ) do
26+ def handle_event ( [ :oban , :job , :exception ] , _measurements , % { job: job } = _metadata , config ) do
27+ if should_report? ( job , config ) do
28+ do_report ( job )
29+ else
30+ :ok
31+ end
32+ end
33+
34+ defp should_report? ( job , config ) do
35+ case Keyword . get ( config , :skip_retries ) do
36+ true -> job . attempt == job . max_attempts
37+ _ -> true
38+ end
39+ end
40+
41+ defp do_report ( job ) do
2742 % { reason: reason , stacktrace: stacktrace } = job . unsaved_error
2843
2944 stacktrace =
@@ -39,15 +54,13 @@ defmodule Sentry.Integrations.Oban.ErrorReporter do
3954 [ inspect ( reason ) ]
4055 end
4156
42- opts =
43- [
44- stacktrace: stacktrace ,
45- tags: % { oban_worker: job . worker , oban_queue: job . queue , oban_state: job . state } ,
46- fingerprint: [ inspect ( job . worker ) ] ++ fingerprint_opts ,
47- extra:
48- Map . take ( job , [ :args , :attempt , :id , :max_attempts , :meta , :queue , :tags , :worker ] ) ,
49- integration_meta: % { oban: % { job: job } }
50- ]
57+ opts = [
58+ stacktrace: stacktrace ,
59+ tags: % { oban_worker: job . worker , oban_queue: job . queue , oban_state: job . state } ,
60+ fingerprint: [ inspect ( job . worker ) ] ++ fingerprint_opts ,
61+ extra: Map . take ( job , [ :args , :attempt , :id , :max_attempts , :meta , :queue , :tags , :worker ] ) ,
62+ integration_meta: % { oban: % { job: job } }
63+ ]
5164
5265 _ =
5366 if is_exception ( reason ) do
0 commit comments