Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Behavioral Changes

- Measure HTTP rate-limit backoff on a monotonic clock instead of the wall clock, so that a device time change no longer lifts or extends an active rate limit ([#6030](https://github.com/getsentry/sentry-java/pull/6030))
- Measure check-in durations on the monotonic clock, so a cron job that spans device sleep reports the time a user would measure instead of the time the CPU was awake ([#6032](https://github.com/getsentry/sentry-java/pull/6032))

### Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.sentry.ScopesAdapter;
import io.sentry.SentryLevel;
import io.sentry.protocol.SentryId;
import io.sentry.time.Stopwatch;
import io.sentry.util.Objects;
import io.sentry.util.TracingUtils;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -91,7 +92,8 @@ public Object invoke(final @NotNull MethodInvocation invocation) throws Throwabl
TracingUtils.startNewTrace(scopes);

@Nullable SentryId checkInId = null;
final long startTime = System.nanoTime();
final @NotNull Stopwatch stopwatch =
Stopwatch.started(scopes.getOptions().getMonotonicClock());
boolean didError = false;

try {
Expand All @@ -105,7 +107,7 @@ public Object invoke(final @NotNull MethodInvocation invocation) throws Throwabl
} finally {
final @NotNull CheckInStatus status = didError ? CheckInStatus.ERROR : CheckInStatus.OK;
CheckIn checkIn = new CheckIn(checkInId, monitorSlug, status);
checkIn.setDuration(DateUtils.nanosToSeconds(System.nanoTime() - startTime));
checkIn.setDuration(DateUtils.nanosToSeconds(stopwatch.elapsedNanos()));
scopes.captureCheckIn(checkIn);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.sentry.ScopesAdapter;
import io.sentry.SentryLevel;
import io.sentry.protocol.SentryId;
import io.sentry.time.Stopwatch;
import io.sentry.util.Objects;
import io.sentry.util.TracingUtils;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -91,7 +92,8 @@ public Object invoke(final @NotNull MethodInvocation invocation) throws Throwabl
TracingUtils.startNewTrace(scopes);

@Nullable SentryId checkInId = null;
final long startTime = System.nanoTime();
final @NotNull Stopwatch stopwatch =
Stopwatch.started(scopes.getOptions().getMonotonicClock());
boolean didError = false;

try {
Expand All @@ -105,7 +107,7 @@ public Object invoke(final @NotNull MethodInvocation invocation) throws Throwabl
} finally {
final @NotNull CheckInStatus status = didError ? CheckInStatus.ERROR : CheckInStatus.OK;
CheckIn checkIn = new CheckIn(checkInId, monitorSlug, status);
checkIn.setDuration(DateUtils.nanosToSeconds(System.nanoTime() - startTime));
checkIn.setDuration(DateUtils.nanosToSeconds(stopwatch.elapsedNanos()));
scopes.captureCheckIn(checkIn);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.sentry.ScopesAdapter;
import io.sentry.SentryLevel;
import io.sentry.protocol.SentryId;
import io.sentry.time.Stopwatch;
import io.sentry.util.Objects;
import io.sentry.util.TracingUtils;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -94,7 +95,8 @@ public Object invoke(final @NotNull MethodInvocation invocation) throws Throwabl
TracingUtils.startNewTrace(scopes);

@Nullable SentryId checkInId = null;
final long startTime = System.nanoTime();
final @NotNull Stopwatch stopwatch =
Stopwatch.started(scopes.getOptions().getMonotonicClock());
boolean didError = false;

try {
Expand All @@ -108,7 +110,7 @@ public Object invoke(final @NotNull MethodInvocation invocation) throws Throwabl
} finally {
final @NotNull CheckInStatus status = didError ? CheckInStatus.ERROR : CheckInStatus.OK;
CheckIn checkIn = new CheckIn(checkInId, monitorSlug, status);
checkIn.setDuration(DateUtils.nanosToSeconds(System.nanoTime() - startTime));
checkIn.setDuration(DateUtils.nanosToSeconds(stopwatch.elapsedNanos()));
scopes.captureCheckIn(checkIn);
}
}
Expand Down
6 changes: 4 additions & 2 deletions sentry/src/main/java/io/sentry/util/CheckInUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.sentry.MonitorConfig;
import io.sentry.Sentry;
import io.sentry.protocol.SentryId;
import io.sentry.time.Stopwatch;
import java.util.List;
import java.util.concurrent.Callable;
import org.jetbrains.annotations.ApiStatus;
Expand Down Expand Up @@ -37,7 +38,8 @@ public static <U> U withCheckIn(
try (final @NotNull ISentryLifecycleToken ignored =
Sentry.forkedScopes("CheckInUtils").makeCurrent()) {
final @NotNull IScopes scopes = Sentry.getCurrentScopes();
final long startTime = System.nanoTime();
final @NotNull Stopwatch stopwatch =
Stopwatch.started(scopes.getOptions().getMonotonicClock());
boolean didError = false;

TracingUtils.startNewTrace(scopes);
Expand All @@ -61,7 +63,7 @@ public static <U> U withCheckIn(
if (environment != null) {
checkIn.setEnvironment(environment);
}
checkIn.setDuration(DateUtils.nanosToSeconds(System.nanoTime() - startTime));
checkIn.setDuration(DateUtils.nanosToSeconds(stopwatch.elapsedNanos()));
scopes.captureCheckIn(checkIn);
}
}
Expand Down
1 change: 1 addition & 0 deletions sentry/src/test/java/io/sentry/util/CheckInUtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class CheckInUtilsTest {
sentry.`when`<Any> { Sentry.forkedScopes(any()) }.then { scopes.forkedScopes("test") }
whenever(scopes.forkedScopes(any())).thenReturn(scopes)
whenever(scopes.makeCurrent()).thenReturn(lifecycleToken)
whenever(scopes.options).thenReturn(SentryOptions())

try {
CheckInUtils.withCheckIn("monitor-1") { throw RuntimeException("thrown on purpose") }
Expand Down
Loading