Skip to content
Merged
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
* <p>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(
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>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 {

Expand Down
Loading