@@ -8,23 +8,23 @@ defmodule Sentry.Integrations.Oban.Cron do
8
8
[ :oban , :job , :exception ]
9
9
]
10
10
11
- @ spec attach_telemetry_handler ( ) :: :ok
12
- def attach_telemetry_handler do
13
- _ = :telemetry . attach_many ( __MODULE__ , @ events , & __MODULE__ . handle_event / 4 , :no_config )
11
+ @ spec attach_telemetry_handler ( keyword ( ) ) :: :ok
12
+ def attach_telemetry_handler ( config ) when is_list ( config ) do
13
+ _ = :telemetry . attach_many ( __MODULE__ , @ events , & __MODULE__ . handle_event / 4 , config )
14
14
:ok
15
15
end
16
16
17
- @ spec handle_event ( [ atom ( ) ] , term ( ) , term ( ) , :no_config ) :: :ok
18
- def handle_event ( event , measurements , metadata , _config )
17
+ @ spec handle_event ( [ atom ( ) ] , term ( ) , term ( ) , keyword ( ) ) :: :ok
18
+ def handle_event ( event , measurements , metadata , config )
19
19
20
20
def handle_event (
21
21
[ :oban , :job , event ] ,
22
22
measurements ,
23
23
% { job: % mod { meta: % { "cron" => true , "cron_expr" => cron_expr } } } = metadata ,
24
- _config
24
+ config
25
25
)
26
26
when event in [ :start , :stop , :exception ] and mod == Oban.Job and is_binary ( cron_expr ) do
27
- _ = handle_event ( event , measurements , metadata )
27
+ _ = handle_oban_job_event ( event , measurements , metadata , config )
28
28
:ok
29
29
end
30
30
@@ -35,16 +35,16 @@ defmodule Sentry.Integrations.Oban.Cron do
35
35
36
36
## Helpers
37
37
38
- defp handle_event ( :start , _measurements , metadata ) do
39
- if opts = job_to_check_in_opts ( metadata . job ) do
38
+ defp handle_oban_job_event ( :start , _measurements , metadata , config ) do
39
+ if opts = job_to_check_in_opts ( metadata . job , config ) do
40
40
opts
41
41
|> Keyword . merge ( status: :in_progress )
42
42
|> Sentry . capture_check_in ( )
43
43
end
44
44
end
45
45
46
- defp handle_event ( :stop , measurements , metadata ) do
47
- if opts = job_to_check_in_opts ( metadata . job ) do
46
+ defp handle_oban_job_event ( :stop , measurements , metadata , config ) do
47
+ if opts = job_to_check_in_opts ( metadata . job , config ) do
48
48
status =
49
49
case metadata . state do
50
50
:success -> :ok
@@ -60,17 +60,26 @@ defmodule Sentry.Integrations.Oban.Cron do
60
60
end
61
61
end
62
62
63
- defp handle_event ( :exception , measurements , metadata ) do
64
- if opts = job_to_check_in_opts ( metadata . job ) do
63
+ defp handle_oban_job_event ( :exception , measurements , metadata , config ) do
64
+ if opts = job_to_check_in_opts ( metadata . job , config ) do
65
65
opts
66
66
|> Keyword . merge ( status: :error , duration: duration_in_seconds ( measurements ) )
67
67
|> Sentry . capture_check_in ( )
68
68
end
69
69
end
70
70
71
- defp job_to_check_in_opts ( job ) when is_struct ( job , Oban.Job ) do
71
+ defp job_to_check_in_opts ( job , config ) when is_struct ( job , Oban.Job ) do
72
72
monitor_config_opts = Sentry.Config . integrations ( ) [ :monitor_config_defaults ]
73
73
74
+ monitor_slug =
75
+ case config [ :monitor_slug_generator ] do
76
+ nil ->
77
+ slugify ( job . worker )
78
+
79
+ { mod , fun } when is_atom ( mod ) and is_atom ( fun ) ->
80
+ mod |> apply ( fun , [ job ] ) |> slugify ( )
81
+ end
82
+
74
83
case Keyword . merge ( monitor_config_opts , schedule_opts ( job ) ) do
75
84
[ ] ->
76
85
nil
@@ -81,7 +90,7 @@ defmodule Sentry.Integrations.Oban.Cron do
81
90
[
82
91
check_in_id: id ,
83
92
# This is already a binary.
84
- monitor_slug: slugify ( job . worker ) ,
93
+ monitor_slug: monitor_slug ,
85
94
monitor_config: monitor_config_opts
86
95
]
87
96
end
0 commit comments