@@ -22,12 +22,14 @@ public final class CheckInUtils {
22
22
*
23
23
* @param monitorSlug - the slug of the monitor
24
24
* @param monitorConfig - configuration of the monitor, can be used for upserting schedule
25
+ * @param environment - the name of the environment
25
26
* @param callable - the {@link Callable} to be called
26
27
* @return the return value of the {@link Callable}
27
28
* @param <U> - the result type of the {@link Callable}
28
29
*/
29
30
public static <U > U withCheckIn (
30
31
final @ NotNull String monitorSlug ,
32
+ final @ Nullable String environment ,
31
33
final @ Nullable MonitorConfig monitorConfig ,
32
34
final @ NotNull Callable <U > callable )
33
35
throws Exception {
@@ -43,6 +45,9 @@ public static <U> U withCheckIn(
43
45
if (monitorConfig != null ) {
44
46
inProgressCheckIn .setMonitorConfig (monitorConfig );
45
47
}
48
+ if (environment != null ) {
49
+ inProgressCheckIn .setEnvironment (environment );
50
+ }
46
51
@ Nullable SentryId checkInId = scopes .captureCheckIn (inProgressCheckIn );
47
52
try {
48
53
return callable .call ();
@@ -52,12 +57,49 @@ public static <U> U withCheckIn(
52
57
} finally {
53
58
final @ NotNull CheckInStatus status = didError ? CheckInStatus .ERROR : CheckInStatus .OK ;
54
59
CheckIn checkIn = new CheckIn (checkInId , monitorSlug , status );
60
+ if (environment != null ) {
61
+ checkIn .setEnvironment (environment );
62
+ }
55
63
checkIn .setDuration (DateUtils .millisToSeconds (System .currentTimeMillis () - startTime ));
56
64
scopes .captureCheckIn (checkIn );
57
65
}
58
66
}
59
67
}
60
68
69
+ /**
70
+ * Helper method to send monitor check-ins for a {@link Callable}
71
+ *
72
+ * @param monitorSlug - the slug of the monitor
73
+ * @param monitorConfig - configuration of the monitor, can be used for upserting schedule
74
+ * @param callable - the {@link Callable} to be called
75
+ * @return the return value of the {@link Callable}
76
+ * @param <U> - the result type of the {@link Callable}
77
+ */
78
+ public static <U > U withCheckIn (
79
+ final @ NotNull String monitorSlug ,
80
+ final @ Nullable MonitorConfig monitorConfig ,
81
+ final @ NotNull Callable <U > callable )
82
+ throws Exception {
83
+ return withCheckIn (monitorSlug , null , monitorConfig , callable );
84
+ }
85
+
86
+ /**
87
+ * Helper method to send monitor check-ins for a {@link Callable}
88
+ *
89
+ * @param monitorSlug - the slug of the monitor
90
+ * @param environment - the name of the environment
91
+ * @param callable - the {@link Callable} to be called
92
+ * @return the return value of the {@link Callable}
93
+ * @param <U> - the result type of the {@link Callable}
94
+ */
95
+ public static <U > U withCheckIn (
96
+ final @ NotNull String monitorSlug ,
97
+ final @ Nullable String environment ,
98
+ final @ NotNull Callable <U > callable )
99
+ throws Exception {
100
+ return withCheckIn (monitorSlug , environment , null , callable );
101
+ }
102
+
61
103
/**
62
104
* Helper method to send monitor check-ins for a {@link Callable}
63
105
*
@@ -68,7 +110,7 @@ public static <U> U withCheckIn(
68
110
*/
69
111
public static <U > U withCheckIn (
70
112
final @ NotNull String monitorSlug , final @ NotNull Callable <U > callable ) throws Exception {
71
- return withCheckIn (monitorSlug , null , callable );
113
+ return withCheckIn (monitorSlug , null , null , callable );
72
114
}
73
115
74
116
/** Checks if a check-in for a monitor (CRON) has been ignored. */
0 commit comments