feat: Add API to retrieve persisted breadcrumbs on Android#4977
feat: Add API to retrieve persisted breadcrumbs on Android#4977
Conversation
Reads breadcrumbs from the Android SDK's PersistingScopeObserver during init and exposes them via SentrySdk.GetPersistedBreadcrumbs(). This allows customers to access breadcrumbs from the previous app session without needing access to internal binding types. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Features ✨
Fixes 🐛
Dependencies ⬆️Deps
Other
🤖 This preview updates automatically when you update the PR. |
|
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4977 +/- ##
=======================================
Coverage 73.87% 73.87%
=======================================
Files 496 496
Lines 17951 17951
Branches 3516 3516
=======================================
+ Hits 13261 13262 +1
+ Misses 3832 3831 -1
Partials 858 858 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The Java SDK returns an unmodifiable list (Collections$UnmodifiableRandomAccessList) which cannot be cast to ArrayList. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The scope observer list may be concurrently modified during init, causing a ConcurrentModificationException. Gracefully return null instead of crashing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… condition Move breadcrumb reading into the OptionsConfigurationCallback, before SentryAndroid.Init() completes and integrations start writing to the QueueFile. Create a temporary PersistingScopeObserver to read from the previous session's data without concurrent modification. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| // Create a temporary observer to read breadcrumbs from the previous session's QueueFile. | ||
| // This must be called before SentryAndroid.Init() completes, to avoid a race condition | ||
| // with breadcrumb-producing integrations that write to the same QueueFile concurrently. | ||
| using var observer = new JavaSdk.Cache.PersistingScopeObserver(nativeOptions); |
There was a problem hiding this comment.
question: could the user code just read the file directly and/or find and read the "breadcrumbs.json" themselves?
We're a bit hesitant of adding an API for a single use case, that is also either pessimizing all other scenarios, or a bit of a "dangerous" API (order of invocations).
There was a problem hiding this comment.
nope, not easily -- the file has a special format and QueueFile is excluded from the bindings, plus, some necessary classes are package-private. Though, theoretically, exposing the QueueFile should be enough -- the rest can be achieved with a bit more code on the user's side
There was a problem hiding this comment.
Maybe a middle ground, we could expose the ReadPersistedBreadcrumbs method publicly so users can call this themselves (before initialising the Android SDK) and dispose of the breadcrumbs once they're done with them.
We wouldn't then call this automatically and store the results for the lifetime of the application in _persistedBreadcrumbs (even users that don't care about this functionality).
That way the functionality is there for folks that need to use it, but everyone else doesn't pay a feature bloat tax.
There was a problem hiding this comment.
yep, that's what I suggested to @Flash0ver internally as well. If y'all are fine with that, we could go that way 👍
Summary
SentrySdk.GetPersistedBreadcrumbs()public API that returns breadcrumbs from the previous app session on AndroidPersistingScopeObserverduring init and caches the resultBreadcrumbobjectsUsage
Test plan
🤖 Generated with Claude Code