@@ -22,12 +22,14 @@ public final class CheckInUtils {
2222 *
2323 * @param monitorSlug - the slug of the monitor
2424 * @param monitorConfig - configuration of the monitor, can be used for upserting schedule
25+ * @param environment - the name of the environment
2526 * @param callable - the {@link Callable} to be called
2627 * @return the return value of the {@link Callable}
2728 * @param <U> - the result type of the {@link Callable}
2829 */
2930 public static <U > U withCheckIn (
3031 final @ NotNull String monitorSlug ,
32+ final @ Nullable String environment ,
3133 final @ Nullable MonitorConfig monitorConfig ,
3234 final @ NotNull Callable <U > callable )
3335 throws Exception {
@@ -43,6 +45,9 @@ public static <U> U withCheckIn(
4345 if (monitorConfig != null ) {
4446 inProgressCheckIn .setMonitorConfig (monitorConfig );
4547 }
48+ if (environment != null ) {
49+ inProgressCheckIn .setEnvironment (environment );
50+ }
4651 @ Nullable SentryId checkInId = scopes .captureCheckIn (inProgressCheckIn );
4752 try {
4853 return callable .call ();
@@ -52,12 +57,49 @@ public static <U> U withCheckIn(
5257 } finally {
5358 final @ NotNull CheckInStatus status = didError ? CheckInStatus .ERROR : CheckInStatus .OK ;
5459 CheckIn checkIn = new CheckIn (checkInId , monitorSlug , status );
60+ if (environment != null ) {
61+ checkIn .setEnvironment (environment );
62+ }
5563 checkIn .setDuration (DateUtils .millisToSeconds (System .currentTimeMillis () - startTime ));
5664 scopes .captureCheckIn (checkIn );
5765 }
5866 }
5967 }
6068
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+
61103 /**
62104 * Helper method to send monitor check-ins for a {@link Callable}
63105 *
@@ -68,7 +110,7 @@ public static <U> U withCheckIn(
68110 */
69111 public static <U > U withCheckIn (
70112 final @ NotNull String monitorSlug , final @ NotNull Callable <U > callable ) throws Exception {
71- return withCheckIn (monitorSlug , null , callable );
113+ return withCheckIn (monitorSlug , null , null , callable );
72114 }
73115
74116 /** Checks if a check-in for a monitor (CRON) has been ignored. */
0 commit comments