Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
b286ad5
Profile main thread when ANR and report ANR profiles to sentry
markushi Nov 12, 2025
a62b5e8
docs(changelog): Add ANR profiling integration entry
markushi Nov 12, 2025
ae66f73
Merge branch 'main' into markushi/feat/anr-profiling
markushi Nov 12, 2025
f226d84
Fix api dump file
markushi Nov 13, 2025
7d423a4
Address PR feedback
markushi Nov 13, 2025
5824f8f
Merge branch 'markushi/feat/anr-profiling' of github.com:getsentry/se…
markushi Nov 13, 2025
6e7fff2
Merge branch 'main' into markushi/feat/anr-profiling
markushi Dec 1, 2025
3d4d952
refactor(anr): Implement lazy file rotation for ANR profiling
markushi Dec 2, 2025
69170ce
Merge branch 'main' into markushi/feat/anr-profiling
markushi Dec 3, 2025
cee86fc
Update Changelog
markushi Dec 3, 2025
49c2e20
Address PR feedback
markushi Dec 4, 2025
93141dd
Improve folding logic, cleanup tests
markushi Dec 16, 2025
a59bf08
Add more tests and address feedback
markushi Dec 16, 2025
5bfff6a
Merge branch 'main' into markushi/feat/anr-profiling
markushi Dec 16, 2025
6c9acd7
Update CHANGELOG.md
markushi Dec 17, 2025
4c95292
Merge branch 'main' into markushi/feat/anr-profiling
markushi Dec 18, 2025
cdd74b9
Merge branch 'main' into markushi/feat/anr-profiling
markushi Jan 29, 2026
e67c713
Address PR feedcback
markushi Jan 30, 2026
0cd877d
Merge branch 'main' into markushi/feat/anr-profiling
markushi Jan 30, 2026
ff3c01e
Merge branch 'main' into markushi/feat/anr-profiling
markushi Feb 11, 2026
47db30e
Merge branch 'markushi/feat/anr-profiling' of github.com:getsentry/se…
markushi Feb 11, 2026
aefa921
Move logic to event processor
markushi Feb 11, 2026
e68c4cf
Update changelog
markushi Feb 11, 2026
e92a82b
Ensure integration is tracked
markushi Feb 11, 2026
6ecd31e
Address PR feedback
markushi Feb 11, 2026
29b2ff0
Fix tests
markushi Feb 11, 2026
a15602b
Match manifest property to convention, enable profiling in sample app
markushi Feb 11, 2026
d33ccfc
Merge branch 'main' into markushi/feat/anr-profiling
markushi Feb 12, 2026
28c7bfa
Add more bound checks and null guards
markushi Feb 12, 2026
aa79a11
Remove outdated meta-data
markushi Feb 12, 2026
175fc39
Properly handle foreground transitions
markushi Feb 12, 2026
aeb7d72
Address PR comments
markushi Feb 12, 2026
61bb712
Address PR feedback
markushi Feb 13, 2026
39229d5
Address PR feedback
markushi Feb 13, 2026
2ff62db
Address PR feedback
markushi Feb 16, 2026
3d502b8
Re-use thread
markushi Feb 26, 2026
44d8bfa
Merge branch 'main' into markushi/feat/anr-profiling
markushi Feb 26, 2026
cd1f4c2
Update Changelop
markushi Feb 26, 2026
8a49e18
Address review
romtsn Feb 26, 2026
5ae3e11
Address PR feedback
markushi Feb 27, 2026
0cc4bba
Merge branch 'main' into markushi/feat/anr-profiling
markushi Mar 4, 2026
034445f
Replace ANR profiling boolean flag with sample-rate (#5156)
markushi Mar 6, 2026
5e8b866
feat(android): Add enableAnrFingerprinting option (#5168)
markushi Mar 6, 2026
ddbe532
Fix tests
markushi Mar 6, 2026
ab98857
Merge branch 'markushi/feat/anr-profiling' of github.com:getsentry/se…
markushi Mar 6, 2026
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
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
<meta-data android:name="io.sentry.screenshot.mask-all-images" android:value="true" />
```
- The `ManifestMetaDataReader` now read the `DIST` ([#5107](https://github.com/getsentry/sentry-java/pull/5107))
- Add new experimental option to capture profiles for ANRs ([#4899](https://github.com/getsentry/sentry-java/pull/4899))
- This feature will capture a stack profile of the main thread when it gets unresponsive
- The profile gets attached to the ANR event on the next app start, providing a flamegraph of the ANR issue on the sentry issue details page
- Enable via `options.setAnrProfilingSampleRate(<sample-rate>)` or AndroidManifest.xml: `<meta-data android:name="io.sentry.anr.profiling.sample-rate" android:value="[0.0-1.0]" />`
- The sample rate controls the probability of collecting a profile for each detected foreground ANR (0.0 to 1.0, null to disable)
- Add `enableAnrFingerprinting` option to reduce ANR noise by assigning static fingerprints to ANR events with system-only stacktraces
- When enabled, ANRs whose stacktraces contain only system frames (e.g. `java.lang` or `android.os`) are grouped into a single issue instead of creating many separate issues
- Enable via `options.setEnableAnrFingerprinting(true)` or AndroidManifest.xml: `<meta-data android:name="io.sentry.anr.enable-fingerprinting" android:value="true" />`

### Fixes

Expand Down Expand Up @@ -168,7 +176,7 @@
- Discard envelopes on `4xx` and `5xx` response ([#4950](https://github.com/getsentry/sentry-java/pull/4950))
- This aims to not overwhelm Sentry after an outage or load shedding (including HTTP 429) where too many events are sent at once

### Feature
### Features

- Add a Tombstone integration that detects native crashes without relying on the NDK integration, but instead using `ApplicationExitInfo.REASON_CRASH_NATIVE` on Android 12+. ([#4933](https://github.com/getsentry/sentry-java/pull/4933))
- Currently exposed via options as an _internal_ API only.
Expand Down
78 changes: 78 additions & 0 deletions sentry-android-core/api/sentry-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ public final class io/sentry/android/core/SentryAndroidDateProvider : io/sentry/
public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/SentryOptions {
public fun <init> ()V
public fun enableAllAutoBreadcrumbs (Z)V
public fun getAnrProfilingSampleRate ()Ljava/lang/Double;
public fun getAnrTimeoutIntervalMillis ()J
public fun getBeforeScreenshotCaptureCallback ()Lio/sentry/android/core/SentryAndroidOptions$BeforeCaptureCallback;
public fun getBeforeViewHierarchyCaptureCallback ()Lio/sentry/android/core/SentryAndroidOptions$BeforeCaptureCallback;
Expand All @@ -357,6 +358,7 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
public fun getScreenshot ()Lio/sentry/android/core/SentryScreenshotOptions;
public fun getStartupCrashDurationThresholdMillis ()J
public fun isAnrEnabled ()Z
public fun isAnrProfilingEnabled ()Z
public fun isAnrReportInDebug ()Z
public fun isAttachAnrThreadDump ()Z
public fun isAttachScreenshot ()Z
Expand All @@ -365,6 +367,7 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
public fun isCollectExternalStorageContext ()Z
public fun isEnableActivityLifecycleBreadcrumbs ()Z
public fun isEnableActivityLifecycleTracingAutoFinish ()Z
public fun isEnableAnrFingerprinting ()Z
public fun isEnableAppComponentBreadcrumbs ()Z
public fun isEnableAppLifecycleBreadcrumbs ()Z
public fun isEnableAutoActivityLifecycleTracing ()Z
Expand All @@ -381,6 +384,7 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
public fun isReportHistoricalTombstones ()Z
public fun isTombstoneEnabled ()Z
public fun setAnrEnabled (Z)V
public fun setAnrProfilingSampleRate (Ljava/lang/Double;)V
public fun setAnrReportInDebug (Z)V
public fun setAnrTimeoutIntervalMillis (J)V
public fun setAttachAnrThreadDump (Z)V
Expand All @@ -393,6 +397,7 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
public fun setDebugImagesLoader (Lio/sentry/android/core/IDebugImagesLoader;)V
public fun setEnableActivityLifecycleBreadcrumbs (Z)V
public fun setEnableActivityLifecycleTracingAutoFinish (Z)V
public fun setEnableAnrFingerprinting (Z)V
public fun setEnableAppComponentBreadcrumbs (Z)V
public fun setEnableAppLifecycleBreadcrumbs (Z)V
public fun setEnableAutoActivityLifecycleTracing (Z)V
Expand Down Expand Up @@ -553,6 +558,79 @@ public final class io/sentry/android/core/ViewHierarchyEventProcessor : io/sentr
public static fun snapshotViewHierarchyAsData (Landroid/app/Activity;Lio/sentry/util/thread/IThreadChecker;Lio/sentry/ISerializer;Lio/sentry/ILogger;)[B
}

public class io/sentry/android/core/anr/AggregatedStackTrace {
public fun <init> ([Ljava/lang/StackTraceElement;IIJF)V
public fun addOccurrence (J)V
public fun getStack ()[Ljava/lang/StackTraceElement;
}

public class io/sentry/android/core/anr/AnrCulpritIdentifier {
public fun <init> ()V
public static fun identify (Ljava/util/List;)Lio/sentry/android/core/anr/AggregatedStackTrace;
public static fun isSystemFrame (Ljava/lang/String;)Z
}

public class io/sentry/android/core/anr/AnrProfile {
public final field endTimeMs J
public final field stacks Ljava/util/List;
public final field startTimeMs J
public fun <init> (Ljava/util/List;)V
}

public class io/sentry/android/core/anr/AnrProfileManager : java/lang/AutoCloseable {
public fun <init> (Lio/sentry/SentryOptions;)V
public fun <init> (Lio/sentry/SentryOptions;Ljava/io/File;)V
public fun add (Lio/sentry/android/core/anr/AnrStackTrace;)V
public fun clear ()V
public fun close ()V
public fun load ()Lio/sentry/android/core/anr/AnrProfile;
}

public class io/sentry/android/core/anr/AnrProfileRotationHelper {
public fun <init> ()V
public static fun deleteLastFile (Ljava/io/File;)Z
public static fun getFileForRecording (Ljava/io/File;)Ljava/io/File;
public static fun getLastFile (Ljava/io/File;)Ljava/io/File;
public static fun rotate ()V
}

public class io/sentry/android/core/anr/AnrProfilingIntegration : io/sentry/Integration, io/sentry/android/core/AppState$AppStateListener, java/io/Closeable, java/lang/Runnable {
public static final field POLLING_INTERVAL_MS J
public static final field THRESHOLD_ANR_MS J
public fun <init> ()V
protected fun checkMainThread (Ljava/lang/Thread;)V
public fun close ()V
protected fun getProfileManager ()Lio/sentry/android/core/anr/AnrProfileManager;
protected fun getState ()Lio/sentry/android/core/anr/AnrProfilingIntegration$MainThreadState;
public fun onBackground ()V
public fun onForeground ()V
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
public fun run ()V
}

protected final class io/sentry/android/core/anr/AnrProfilingIntegration$MainThreadState : java/lang/Enum {
public static final field ANR_DETECTED Lio/sentry/android/core/anr/AnrProfilingIntegration$MainThreadState;
public static final field IDLE Lio/sentry/android/core/anr/AnrProfilingIntegration$MainThreadState;
public static final field SUSPICIOUS Lio/sentry/android/core/anr/AnrProfilingIntegration$MainThreadState;
public static fun valueOf (Ljava/lang/String;)Lio/sentry/android/core/anr/AnrProfilingIntegration$MainThreadState;
public static fun values ()[Lio/sentry/android/core/anr/AnrProfilingIntegration$MainThreadState;
}

public final class io/sentry/android/core/anr/AnrStackTrace : java/lang/Comparable {
public final field stack [Ljava/lang/StackTraceElement;
public final field timestampMs J
public fun <init> (J[Ljava/lang/StackTraceElement;)V
public fun compareTo (Lio/sentry/android/core/anr/AnrStackTrace;)I
public synthetic fun compareTo (Ljava/lang/Object;)I
public static fun deserialize (Ljava/io/DataInputStream;)Lio/sentry/android/core/anr/AnrStackTrace;
public fun serialize (Ljava/io/DataOutputStream;)V
}

public final class io/sentry/android/core/anr/StackTraceConverter {
public fun <init> ()V
public static fun convert (Lio/sentry/android/core/anr/AnrProfile;)Lio/sentry/protocol/profiling/SentryProfile;
}

public final class io/sentry/android/core/cache/AndroidEnvelopeCache : io/sentry/cache/EnvelopeCache {
public static final field LAST_ANR_MARKER_LABEL Ljava/lang/String;
public static final field LAST_ANR_REPORT Ljava/lang/String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import io.sentry.SendFireAndForgetOutboxSender;
import io.sentry.SentryLevel;
import io.sentry.SentryOpenTelemetryMode;
import io.sentry.android.core.anr.AnrProfileRotationHelper;
import io.sentry.android.core.anr.AnrProfilingIntegration;
import io.sentry.android.core.cache.AndroidEnvelopeCache;
import io.sentry.android.core.internal.debugmeta.AssetsDebugMetaLoader;
import io.sentry.android.core.internal.gestures.AndroidViewGestureTargetLocator;
Expand Down Expand Up @@ -135,6 +137,8 @@ static void loadDefaultAndMetadataOptions(

options.setCacheDirPath(getCacheDir(finalContext).getAbsolutePath());

AnrProfileRotationHelper.rotate();

readDefaultOptionValues(options, finalContext, buildInfoProvider);
AppState.getInstance().registerLifecycleObserver(options);
options.activate();
Expand Down Expand Up @@ -397,6 +401,8 @@ static void installDefaultIntegrations(
// it to set the replayId in case of an ANR
options.addIntegration(AnrIntegrationFactory.create(context, buildInfoProvider));

options.addIntegration(new AnrProfilingIntegration());

// registerActivityLifecycleCallbacks is only available if Context is an AppContext
if (context instanceof Application) {
options.addIntegration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,18 @@ void reportANR(
message = "Background " + message;
}

final ApplicationNotResponding error = new ApplicationNotResponding(message, anr.getThread());
final @Nullable Thread thread = anr.getThread();
final @NotNull ApplicationNotResponding error;
if (thread == null) {
error = new ApplicationNotResponding(message);
} else {
error = new ApplicationNotResponding(message, thread);
}

final Mechanism mechanism = new Mechanism();
mechanism.setType("ANR");

return new ExceptionMechanismException(mechanism, error, error.getThread(), true);
return new ExceptionMechanismException(mechanism, error, thread, true);
}

@TestOnly
Expand Down
Loading
Loading