diff --git a/CHANGELOG.md b/CHANGELOG.md index 2087ecfce3..2fc2f21790 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ - Add `Session.State.Unhandled` for unhandled errors that do not terminate the process ([#5919](https://github.com/getsentry/sentry-java/pull/5919)) + +### Improvements + +- Move ANR profiling out of experimental ([#6042](https://github.com/getsentry/sentry-java/pull/6042)) + ### Fixes - Keep dropped tombstone and ANR events dropped, instead of reporting the same app exit again at every app start ([#6002](https://github.com/getsentry/sentry-java/pull/6002)) diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroidOptions.java b/sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroidOptions.java index 615db97a28..66a3700d38 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroidOptions.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroidOptions.java @@ -277,6 +277,10 @@ public interface BeforeCaptureCallback { */ private final @NotNull SentryScreenshotOptions screenshot = new SentryScreenshotOptions(); + /** + * Sample rate for capturing main-thread stack profiles when a foreground ANR is detected. {@code + * null} disables ANR profiling (default). Values must be between {@code 0.0} and {@code 1.0}. + */ private @Nullable Double anrProfilingSampleRate; private boolean enableAnrFingerprinting = true; @@ -823,10 +827,25 @@ public void setEnableSystemEventBreadcrumbsExtras( return screenshot; } + /** + * Returns the sample rate used when deciding whether to capture a main-thread stack profile for a + * detected foreground ANR. + * + * @return the ANR profiling sample rate, or {@code null} when ANR profiling is disabled + */ public @Nullable Double getAnrProfilingSampleRate() { return anrProfilingSampleRate; } + /** + * Sets the sample rate for capturing main-thread stack profiles when a foreground ANR is + * detected. The profile is attached to the ANR event on the next app start. + * + *
Use {@code null} to disable ANR profiling (default). Values must be between {@code 0.0} and + * {@code 1.0}. + * + * @param anrProfilingSampleRate the sample rate, or {@code null} to disable + */ public void setAnrProfilingSampleRate(final @Nullable Double anrProfilingSampleRate) { if (!SampleRateUtils.isValidSampleRate(anrProfilingSampleRate)) { throw new IllegalArgumentException( @@ -837,6 +856,12 @@ public void setAnrProfilingSampleRate(final @Nullable Double anrProfilingSampleR this.anrProfilingSampleRate = anrProfilingSampleRate; } + /** + * Returns whether ANR profiling is enabled. ANR profiling is enabled when {@link + * #getAnrProfilingSampleRate()} is non-null and greater than {@code 0.0}. + * + * @return {@code true} if ANR profiling is enabled + */ public boolean isAnrProfilingEnabled() { return anrProfilingSampleRate != null && anrProfilingSampleRate > 0; } diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/anr/AnrProfilingIntegration.java b/sentry-android-core/src/main/java/io/sentry/android/core/anr/AnrProfilingIntegration.java index 97ec043424..3cb0bea4b0 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/anr/AnrProfilingIntegration.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/anr/AnrProfilingIntegration.java @@ -27,6 +27,13 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; +/** + * Captures main-thread stack profiles while the app is unresponsive and attaches them to ANR events + * on the next app start. + * + *
Enable via {@link SentryAndroidOptions#setAnrProfilingSampleRate(Double)} or the {@code + * io.sentry.anr.profiling.sample-rate} manifest metadata. + */ public class AnrProfilingIntegration implements Integration, Closeable, AppState.AppStateListener, Runnable {