Skip to content

Commit

Permalink
Add API for sending checkins (CRONS) manually (#2935)
Browse files Browse the repository at this point in the history
  • Loading branch information
adinauer committed Sep 19, 2023
1 parent 6c21863 commit 8d29d97
Show file tree
Hide file tree
Showing 28 changed files with 1,388 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Add `sendModules` option for disable sending modules ([#2926](https://github.com/getsentry/sentry-java/pull/2926))
- Send `db.system` and `db.name` in span data for androidx.sqlite spans ([#2928](https://github.com/getsentry/sentry-java/pull/2928))
- Add API for sending checkins (CRONS) manually ([#2935](https://github.com/getsentry/sentry-java/pull/2935))

### Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.lifecycle.Lifecycle.Event.ON_STOP
import androidx.lifecycle.LifecycleRegistry
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.sentry.CheckIn
import io.sentry.Hint
import io.sentry.ISentryClient
import io.sentry.ProfilingTraceData
Expand Down Expand Up @@ -162,5 +163,9 @@ class SessionTrackingIntegrationTest {
): SentryId {
TODO("Not yet implemented")
}

override fun captureCheckIn(checkIn: CheckIn, scope: Scope?, hint: Hint?): SentryId {
TODO("Not yet implemented")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package io.sentry.samples.spring.boot.jakarta;

import io.sentry.CheckIn;
import io.sentry.CheckInStatus;
import io.sentry.DateUtils;
import io.sentry.Sentry;
import io.sentry.protocol.SentryId;
import io.sentry.spring.jakarta.tracing.SentryTransaction;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
Expand All @@ -16,9 +22,24 @@ public class CustomJob {

private static final Logger LOGGER = LoggerFactory.getLogger(CustomJob.class);

@Scheduled(fixedRate = 3 * 1000L)
@Scheduled(fixedRate = 3 * 60 * 1000L)
void execute() throws InterruptedException {
LOGGER.info("Executing scheduled job");
Thread.sleep(2000L);
final @NotNull SentryId checkInId =
Sentry.captureCheckIn(new CheckIn("my_monitor_slug", CheckInStatus.IN_PROGRESS));
final long startTime = System.currentTimeMillis();
boolean didError = false;
try {
LOGGER.info("Executing scheduled job");
Thread.sleep(2000L);
Sentry.captureCheckIn(new CheckIn(checkInId, "my_monitor_slug", CheckInStatus.OK));
} catch (Throwable t) {
didError = true;
throw t;
} finally {
final @NotNull CheckInStatus status = didError ? CheckInStatus.ERROR : CheckInStatus.OK;
CheckIn checkIn = new CheckIn(checkInId, "my_monitor_slug", status);
checkIn.setDuration(DateUtils.millisToSeconds(System.currentTimeMillis() - startTime));
Sentry.captureCheckIn(checkIn);
}
}
}
153 changes: 153 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,57 @@ public final class io/sentry/BuildConfig {
public static final field VERSION_NAME Ljava/lang/String;
}

public final class io/sentry/CheckIn : io/sentry/JsonSerializable, io/sentry/JsonUnknown {
public fun <init> (Lio/sentry/protocol/SentryId;Ljava/lang/String;Lio/sentry/CheckInStatus;)V
public fun <init> (Lio/sentry/protocol/SentryId;Ljava/lang/String;Ljava/lang/String;)V
public fun <init> (Ljava/lang/String;Lio/sentry/CheckInStatus;)V
public fun getCheckInId ()Lio/sentry/protocol/SentryId;
public fun getContexts ()Lio/sentry/MonitorContexts;
public fun getDuration ()Ljava/lang/Double;
public fun getEnvironment ()Ljava/lang/String;
public fun getMonitorConfig ()Lio/sentry/MonitorConfig;
public fun getMonitorSlug ()Ljava/lang/String;
public fun getRelease ()Ljava/lang/String;
public fun getStatus ()Ljava/lang/String;
public fun getUnknown ()Ljava/util/Map;
public fun serialize (Lio/sentry/ObjectWriter;Lio/sentry/ILogger;)V
public fun setDuration (Ljava/lang/Double;)V
public fun setEnvironment (Ljava/lang/String;)V
public fun setMonitorConfig (Lio/sentry/MonitorConfig;)V
public fun setMonitorSlug (Ljava/lang/String;)V
public fun setRelease (Ljava/lang/String;)V
public fun setStatus (Lio/sentry/CheckInStatus;)V
public fun setStatus (Ljava/lang/String;)V
public fun setUnknown (Ljava/util/Map;)V
}

public final class io/sentry/CheckIn$Deserializer : io/sentry/JsonDeserializer {
public fun <init> ()V
public fun deserialize (Lio/sentry/JsonObjectReader;Lio/sentry/ILogger;)Lio/sentry/CheckIn;
public synthetic fun deserialize (Lio/sentry/JsonObjectReader;Lio/sentry/ILogger;)Ljava/lang/Object;
}

public final class io/sentry/CheckIn$JsonKeys {
public static final field CHECK_IN_ID Ljava/lang/String;
public static final field CONTEXTS Ljava/lang/String;
public static final field DURATION Ljava/lang/String;
public static final field ENVIRONMENT Ljava/lang/String;
public static final field MONITOR_CONFIG Ljava/lang/String;
public static final field MONITOR_SLUG Ljava/lang/String;
public static final field RELEASE Ljava/lang/String;
public static final field STATUS Ljava/lang/String;
public fun <init> ()V
}

public final class io/sentry/CheckInStatus : java/lang/Enum {
public static final field ERROR Lio/sentry/CheckInStatus;
public static final field IN_PROGRESS Lio/sentry/CheckInStatus;
public static final field OK Lio/sentry/CheckInStatus;
public fun apiName ()Ljava/lang/String;
public static fun valueOf (Ljava/lang/String;)Lio/sentry/CheckInStatus;
public static fun values ()[Lio/sentry/CheckInStatus;
}

public final class io/sentry/CpuCollectionData {
public fun <init> (JD)V
public fun getCpuUsagePercentage ()D
Expand Down Expand Up @@ -354,6 +405,7 @@ public final class io/sentry/Hub : io/sentry/IHub {
public fun <init> (Lio/sentry/SentryOptions;)V
public fun addBreadcrumb (Lio/sentry/Breadcrumb;Lio/sentry/Hint;)V
public fun bindClient (Lio/sentry/ISentryClient;)V
public fun captureCheckIn (Lio/sentry/CheckIn;)Lio/sentry/protocol/SentryId;
public fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/Hint;)Lio/sentry/protocol/SentryId;
public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/protocol/SentryId;
public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/Hint;Lio/sentry/ScopeCallback;)Lio/sentry/protocol/SentryId;
Expand Down Expand Up @@ -400,6 +452,7 @@ public final class io/sentry/Hub : io/sentry/IHub {
public final class io/sentry/HubAdapter : io/sentry/IHub {
public fun addBreadcrumb (Lio/sentry/Breadcrumb;Lio/sentry/Hint;)V
public fun bindClient (Lio/sentry/ISentryClient;)V
public fun captureCheckIn (Lio/sentry/CheckIn;)Lio/sentry/protocol/SentryId;
public fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/Hint;)Lio/sentry/protocol/SentryId;
public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/protocol/SentryId;
public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/Hint;Lio/sentry/ScopeCallback;)Lio/sentry/protocol/SentryId;
Expand Down Expand Up @@ -464,6 +517,7 @@ public abstract interface class io/sentry/IHub {
public fun addBreadcrumb (Ljava/lang/String;)V
public fun addBreadcrumb (Ljava/lang/String;Ljava/lang/String;)V
public abstract fun bindClient (Lio/sentry/ISentryClient;)V
public abstract fun captureCheckIn (Lio/sentry/CheckIn;)Lio/sentry/protocol/SentryId;
public fun captureEnvelope (Lio/sentry/SentryEnvelope;)Lio/sentry/protocol/SentryId;
public abstract fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/Hint;)Lio/sentry/protocol/SentryId;
public fun captureEvent (Lio/sentry/SentryEvent;)Lio/sentry/protocol/SentryId;
Expand Down Expand Up @@ -563,6 +617,7 @@ public abstract interface class io/sentry/IScopeObserver {
}

public abstract interface class io/sentry/ISentryClient {
public abstract fun captureCheckIn (Lio/sentry/CheckIn;Lio/sentry/Scope;Lio/sentry/Hint;)Lio/sentry/protocol/SentryId;
public fun captureEnvelope (Lio/sentry/SentryEnvelope;)Lio/sentry/protocol/SentryId;
public abstract fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/Hint;)Lio/sentry/protocol/SentryId;
public fun captureEvent (Lio/sentry/SentryEvent;)Lio/sentry/protocol/SentryId;
Expand Down Expand Up @@ -850,6 +905,99 @@ public final class io/sentry/MemoryCollectionData {
public fun getUsedNativeMemory ()J
}

public final class io/sentry/MonitorConfig : io/sentry/JsonSerializable, io/sentry/JsonUnknown {
public fun <init> (Lio/sentry/MonitorSchedule;)V
public fun getCheckinMargin ()Ljava/lang/Long;
public fun getMaxRuntime ()Ljava/lang/Long;
public fun getSchedule ()Lio/sentry/MonitorSchedule;
public fun getTimezone ()Ljava/lang/String;
public fun getUnknown ()Ljava/util/Map;
public fun serialize (Lio/sentry/ObjectWriter;Lio/sentry/ILogger;)V
public fun setCheckinMargin (Ljava/lang/Long;)V
public fun setMaxRuntime (Ljava/lang/Long;)V
public fun setSchedule (Lio/sentry/MonitorSchedule;)V
public fun setTimezone (Ljava/lang/String;)V
public fun setUnknown (Ljava/util/Map;)V
}

public final class io/sentry/MonitorConfig$Deserializer : io/sentry/JsonDeserializer {
public fun <init> ()V
public fun deserialize (Lio/sentry/JsonObjectReader;Lio/sentry/ILogger;)Lio/sentry/MonitorConfig;
public synthetic fun deserialize (Lio/sentry/JsonObjectReader;Lio/sentry/ILogger;)Ljava/lang/Object;
}

public final class io/sentry/MonitorConfig$JsonKeys {
public static final field CHECKIN_MARGIN Ljava/lang/String;
public static final field MAX_RUNTIME Ljava/lang/String;
public static final field SCHEDULE Ljava/lang/String;
public static final field TIMEZONE Ljava/lang/String;
public fun <init> ()V
}

public final class io/sentry/MonitorContexts : java/util/concurrent/ConcurrentHashMap, io/sentry/JsonSerializable {
public fun <init> ()V
public fun <init> (Lio/sentry/MonitorContexts;)V
public fun getTrace ()Lio/sentry/SpanContext;
public fun serialize (Lio/sentry/ObjectWriter;Lio/sentry/ILogger;)V
public fun setTrace (Lio/sentry/SpanContext;)V
}

public final class io/sentry/MonitorContexts$Deserializer : io/sentry/JsonDeserializer {
public fun <init> ()V
public fun deserialize (Lio/sentry/JsonObjectReader;Lio/sentry/ILogger;)Lio/sentry/MonitorContexts;
public synthetic fun deserialize (Lio/sentry/JsonObjectReader;Lio/sentry/ILogger;)Ljava/lang/Object;
}

public final class io/sentry/MonitorSchedule : io/sentry/JsonSerializable, io/sentry/JsonUnknown {
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
public static fun crontab (Ljava/lang/String;)Lio/sentry/MonitorSchedule;
public fun getType ()Ljava/lang/String;
public fun getUnit ()Ljava/lang/String;
public fun getUnknown ()Ljava/util/Map;
public fun getValue ()Ljava/lang/String;
public static fun interval (Ljava/lang/Integer;Lio/sentry/MonitorScheduleUnit;)Lio/sentry/MonitorSchedule;
public fun serialize (Lio/sentry/ObjectWriter;Lio/sentry/ILogger;)V
public fun setType (Ljava/lang/String;)V
public fun setUnit (Lio/sentry/MonitorScheduleUnit;)V
public fun setUnit (Ljava/lang/String;)V
public fun setUnknown (Ljava/util/Map;)V
public fun setValue (Ljava/lang/Integer;)V
public fun setValue (Ljava/lang/String;)V
}

public final class io/sentry/MonitorSchedule$Deserializer : io/sentry/JsonDeserializer {
public fun <init> ()V
public fun deserialize (Lio/sentry/JsonObjectReader;Lio/sentry/ILogger;)Lio/sentry/MonitorSchedule;
public synthetic fun deserialize (Lio/sentry/JsonObjectReader;Lio/sentry/ILogger;)Ljava/lang/Object;
}

public final class io/sentry/MonitorSchedule$JsonKeys {
public static final field TYPE Ljava/lang/String;
public static final field UNIT Ljava/lang/String;
public static final field VALUE Ljava/lang/String;
public fun <init> ()V
}

public final class io/sentry/MonitorScheduleType : java/lang/Enum {
public static final field CRONTAB Lio/sentry/MonitorScheduleType;
public static final field INTERVAL Lio/sentry/MonitorScheduleType;
public fun apiName ()Ljava/lang/String;
public static fun valueOf (Ljava/lang/String;)Lio/sentry/MonitorScheduleType;
public static fun values ()[Lio/sentry/MonitorScheduleType;
}

public final class io/sentry/MonitorScheduleUnit : java/lang/Enum {
public static final field DAY Lio/sentry/MonitorScheduleUnit;
public static final field HOUR Lio/sentry/MonitorScheduleUnit;
public static final field MINUTE Lio/sentry/MonitorScheduleUnit;
public static final field MONTH Lio/sentry/MonitorScheduleUnit;
public static final field WEEK Lio/sentry/MonitorScheduleUnit;
public static final field YEAR Lio/sentry/MonitorScheduleUnit;
public fun apiName ()Ljava/lang/String;
public static fun valueOf (Ljava/lang/String;)Lio/sentry/MonitorScheduleUnit;
public static fun values ()[Lio/sentry/MonitorScheduleUnit;
}

public final class io/sentry/NoOpEnvelopeReader : io/sentry/IEnvelopeReader {
public static fun getInstance ()Lio/sentry/NoOpEnvelopeReader;
public fun read (Ljava/io/InputStream;)Lio/sentry/SentryEnvelope;
Expand All @@ -858,6 +1006,7 @@ public final class io/sentry/NoOpEnvelopeReader : io/sentry/IEnvelopeReader {
public final class io/sentry/NoOpHub : io/sentry/IHub {
public fun addBreadcrumb (Lio/sentry/Breadcrumb;Lio/sentry/Hint;)V
public fun bindClient (Lio/sentry/ISentryClient;)V
public fun captureCheckIn (Lio/sentry/CheckIn;)Lio/sentry/protocol/SentryId;
public fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/Hint;)Lio/sentry/protocol/SentryId;
public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/protocol/SentryId;
public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/Hint;Lio/sentry/ScopeCallback;)Lio/sentry/protocol/SentryId;
Expand Down Expand Up @@ -1310,6 +1459,7 @@ public final class io/sentry/Sentry {
public static fun addBreadcrumb (Ljava/lang/String;)V
public static fun addBreadcrumb (Ljava/lang/String;Ljava/lang/String;)V
public static fun bindClient (Lio/sentry/ISentryClient;)V
public static fun captureCheckIn (Lio/sentry/CheckIn;)Lio/sentry/protocol/SentryId;
public static fun captureEvent (Lio/sentry/SentryEvent;)Lio/sentry/protocol/SentryId;
public static fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/protocol/SentryId;
public static fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/Hint;Lio/sentry/ScopeCallback;)Lio/sentry/protocol/SentryId;
Expand Down Expand Up @@ -1456,6 +1606,7 @@ public final class io/sentry/SentryBaseEvent$Serializer {
}

public final class io/sentry/SentryClient : io/sentry/ISentryClient {
public fun captureCheckIn (Lio/sentry/CheckIn;Lio/sentry/Scope;Lio/sentry/Hint;)Lio/sentry/protocol/SentryId;
public fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/Hint;)Lio/sentry/protocol/SentryId;
public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/Scope;Lio/sentry/Hint;)Lio/sentry/protocol/SentryId;
public fun captureSession (Lio/sentry/Session;Lio/sentry/Hint;)V
Expand Down Expand Up @@ -1530,6 +1681,7 @@ public final class io/sentry/SentryEnvelopeHeader$JsonKeys {

public final class io/sentry/SentryEnvelopeItem {
public static fun fromAttachment (Lio/sentry/ISerializer;Lio/sentry/ILogger;Lio/sentry/Attachment;J)Lio/sentry/SentryEnvelopeItem;
public static fun fromCheckIn (Lio/sentry/ISerializer;Lio/sentry/CheckIn;)Lio/sentry/SentryEnvelopeItem;
public static fun fromClientReport (Lio/sentry/ISerializer;Lio/sentry/clientreport/ClientReport;)Lio/sentry/SentryEnvelopeItem;
public static fun fromEvent (Lio/sentry/ISerializer;Lio/sentry/SentryBaseEvent;)Lio/sentry/SentryEnvelopeItem;
public static fun fromProfilingTrace (Lio/sentry/ProfilingTraceData;JLio/sentry/ISerializer;)Lio/sentry/SentryEnvelopeItem;
Expand Down Expand Up @@ -1648,6 +1800,7 @@ public final class io/sentry/SentryIntegrationPackageStorage {

public final class io/sentry/SentryItemType : java/lang/Enum, io/sentry/JsonSerializable {
public static final field Attachment Lio/sentry/SentryItemType;
public static final field CheckIn Lio/sentry/SentryItemType;
public static final field ClientReport Lio/sentry/SentryItemType;
public static final field Event Lio/sentry/SentryItemType;
public static final field Profile Lio/sentry/SentryItemType;
Expand Down

0 comments on commit 8d29d97

Please sign in to comment.