1
1
defmodule ObanErrorReporter do
2
+ use Plausible
2
3
require Logger
3
4
4
5
def handle_event ( name , measurements , metadata , _ ) do
@@ -21,20 +22,17 @@ defmodule ObanErrorReporter do
21
22
|> Map . merge ( measure )
22
23
23
24
on_job_exception ( job )
24
-
25
- Sentry . capture_exception ( meta . reason , stacktrace: meta . stacktrace , extra: extra )
25
+ capture_error ( meta , extra )
26
26
end
27
27
28
28
defp handle_event ( [ :oban , :notifier , :exception ] , _timing , meta ) do
29
29
extra = Map . take ( meta , ~w( channel payload) a )
30
-
31
- Sentry . capture_exception ( meta . reason , stacktrace: meta . stacktrace , extra: extra )
30
+ capture_error ( meta , extra )
32
31
end
33
32
34
33
defp handle_event ( [ :oban , :plugin , :exception ] , _timing , meta ) do
35
34
extra = Map . take ( meta , ~w( plugin) a )
36
-
37
- Sentry . capture_exception ( meta . reason , stacktrace: meta . stacktrace , extra: extra )
35
+ capture_error ( meta , extra )
38
36
end
39
37
40
38
defp on_job_exception ( % Oban.Job {
@@ -65,4 +63,16 @@ defmodule ObanErrorReporter do
65
63
end
66
64
67
65
defp on_job_exception ( _job ) , do: :ignore
66
+
67
+ # Logs the error and sends it to Sentry
68
+ defp capture_error ( meta , extra ) do
69
+ Logger . error (
70
+ # this message is ignored by Sentry
71
+ "Background job (#{ inspect ( extra ) } ) failed:\n \n " <>
72
+ Exception . format ( :error , meta . reason , meta . stacktrace ) ,
73
+ # Sentry report is built entirely from crash_reason
74
+ crash_reason: { meta . reason , meta . stacktrace } ,
75
+ sentry: % { extra: extra }
76
+ )
77
+ end
68
78
end
0 commit comments