Repository navigation
chore(android): generate the binding for Java's IScope - #6016
Conversation
The binding generator left out io.sentry.IScope. ISentryClient takes ProfileChunk and ProfilingTraceData, which Metadata.xml removes, so the generator drops ISentryClient. IScope uses it in getClient() and bindClient(), so the generator dropped IScope too, along with IScopeCallback, IScopeObserver and every getter that returns a scope. A suppressed BG8503 warning was the only sign of it. Removing those two IScope members lets the generator bind IScope. ScopesAdapter now has Scope, IsolationScope and GlobalScope, so code can read a Java scope's replay id without the hand-written JNI that #6001 uses today. Refs #6001 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PR risk: mediumFor commit Main concerns: public contract. Rules that block low also fired:
This label is a hint for reviewers, not an approval. |
There was a problem hiding this comment.
Good to approve, with optional comments
Removing IScope.getClient()/bindClient() in Metadata.xml lets the generator bind IScope and its dependents. That fixes the cause (the ISentryClient cascade) instead of hand-writing JNI around it. The new types stay internal, and nothing in the SDK used the removed members.
- Optional: nothing uses the new types until #6001. If this merges alone, every Android app carries the ~90 KB per target (it isn't trimmed) for no benefit. Consider merging it together with or right before #6001.
- Optional: no test checks that
IScopestays bound. With the BG warnings suppressed insrc/Sentry.Bindings.Android/Sentry.Bindings.Android.csproj, a Java SDK bump could drop it silently again. Once #6001 calls the binding, a missing type fails the build, so this matters only until then.
This is an automated preliminary review.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6016 +/- ##
=======================================
Coverage 78.14% 78.15%
=======================================
Files 537 537
Lines 20077 20077
Branches 4041 4041
=======================================
+ Hits 15689 15691 +2
+ Misses 3544 3543 -1
+ Partials 844 843 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The comment now names the members by what they use rather than a count, and states the generator behavior that makes the rule necessary: one invalid member drops the whole interface. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@bitsandfoxes Once this PR merges, #6001 can replace its hand-written JNI read with the |
#6016 generates the binding for io.sentry.IScope, so ScopesAdapter exposes Scope, IsolationScope and GlobalScope. That replaces the hand-written JNI lookups, and the ProGuard rules that kept them by name: the .NET build already keeps what managed code calls. The Android device test now puts a replay id on the global scope and checks the read returns it, since a renamed Java method would now fail the build instead. As suggested by @ric-oliv in review. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
) * Let an SDK supply the replay session that captures error replays An SDK that records replays itself (Unity on Android) sets an internal replay session on the options. The hub uses it for the replay id of the dynamic sampling context, and the client asks it to capture the replay for each error event that passed BeforeSend and sampling. The event gets its own copy of the dynamic sampling context with the replay id the session returned, or without one when it returned none. Without a supplied session, nothing changes. * Give non-error events the replay that's active when they're sent With a replay session supplied by an SDK, the dynamic sampling context of events without an exception gets the session's active replay id, or none when no replay is active, instead of the one cached on the propagation context when it was created. The event gets its own copy when the id differs; the shared context is never changed. * Open the replay hook to Unity's iOS assemblies and cover its edge cases Sentry.Unity.iOS and its tests can see the internal replay session, so Unity on iOS can supply one like Unity on Android does. New tests cover the hub reading the replay session from the options, a replay session that throws, and a capture that returns an empty replay id. Co-Authored-By: Claude <noreply@anthropic.com> * fix(maui): capture the on-error replay for errors captured in C# On Android and iOS, errors captured by the .NET SDK now capture the native SDK's buffered session replay, and the event's trace header carries that replay's id. Events without an exception carry the id of the replay that is recording, read from the native scope. Binds SentryObjCInternalReplayApi (capture, replayId) from sentry-cocoa. Co-Authored-By: Claude <noreply@anthropic.com> * Give the active transaction the replay its error captured When an error inside a transaction captures a replay and the transaction's dynamic sampling context has no replay id yet, the transaction gets a copy of it with the captured id. The transaction then goes out with the replay, and so does the baggage of outgoing requests made in it. A copy rather than a change in place, since envelopes of earlier errors in the transaction may still be queued with the old one. Co-Authored-By: Claude <noreply@anthropic.com> * Leave an empty dynamic sampling context without a replay id A transaction whose dynamic sampling context is empty doesn't propagate one, because the SDK isn't the head of the trace. An error captured in it that captures a replay no longer gives that context, or the event's copy of it, a lone replay id without the trace id and public key. Co-Authored-By: Claude <noreply@anthropic.com> * Cover the replay id given to an unsampled transaction Co-Authored-By: Claude <noreply@anthropic.com> * Verify on-error replays in the MAUI sample on Android and iOS The MAUI sample ran with replays on errors only (SessionSampleRate 0, OnErrorSampleRate 1.0) and sent to sentry-sdks/z-dotnet-maui. It finished a transaction, waited, then captured a C# exception from a background thread while a second transaction was open on the scope. The sample changes are not committed. Android (API 34 emulator, sentry-java 8.65.1): - error e9e582ba69e048b5b3fcbcb9360ea3eb: replay_id 4e4225888ed04cd9946c3868e7f09235 - replay 4e4225888ed04cd9946c3868e7f09235: buffer, linked to that error - open transaction c308a72b35944dcc91185a3bd6883d9b: same replay_id - earlier transaction 67cd93d4334248b1bd0039baa2422c16: no replay_id iOS (iPhone 17 simulator, iOS 27.0, sentry-cocoa 9.35.0): - error 02a6076f08b44689b8624b080fc7d193: replay_id 3f5c4385153d4caaa05a586722169c17 - replay 3f5c4385153d4caaa05a586722169c17: buffer, linked to that error - open transaction 9e4ce6789db149a89807919783e5dd9f: same replay_id - earlier transaction d5c28af50dc846b7936482653bf7c855: no replay_id Co-Authored-By: Claude <noreply@anthropic.com> * Skip the iOS replay capture when replay is off, and keep the active id on timeout On iOS, an error event no longer hops to the main thread when session replay isn't enabled in the current options. When the main-thread capture times out, the event keeps the active replay id from the scope, as Android does when the native capture gives no id. Co-Authored-By: Claude <noreply@anthropic.com> * Cover the replay session's desktop capture and drop an unreachable branch A desktop test now checks that the built-in replay session captures no replay off mobile. The crash check compares with true instead of falling back on a null that SentryExceptions never returns. Co-Authored-By: Claude <noreply@anthropic.com> * Keep the Java scope getters the replay session reads by name The replay session reads the Java scope's replay id through JNI lookups on io.sentry.IScopes (getScope, getIsolationScope, getGlobalScope) and io.sentry.IScope (getReplayId). Keep rules stop R8 from renaming or removing them in a shrunk or obfuscated release build. Co-Authored-By: Claude <noreply@anthropic.com> * Keep only the replay session tests that check something the others don't An Android device test now reads the Java scopes' replay id through the JNI lookups directly, so a wrong class, method name or signature fails it. The tests that only repeat a null result or cover a line are gone, and CaptureReplay has a declaration per platform, the desktop one as before. Co-Authored-By: Claude <noreply@anthropic.com> * Leave the span processor's replay session as it is Transactions the OpenTelemetry span processor starts go through Hub.StartTransaction, which sets the replay id on their dynamic sampling context from the Hub's session: options.ReplaySession, else the built-in one. The Hub, the client and the span processor therefore read the same session, and a frontend's baggage replay_id is kept when that session has no active replay. Co-Authored-By: Claude <noreply@anthropic.com> * Skip the Android replay capture when session replay is off Android's CaptureReplay returns before reaching the Java replay controller when session replay isn't enabled in the options, as iOS already does. A one-line comment on IsCrash says why it is narrower than HasUnhandledTerminalException(): Java treats a terminating capture as a crash, so a false positive leaves the replay for the next launch and sends no more segments in this process. Co-Authored-By: Claude <noreply@anthropic.com> * Say what a false crash costs the Java replay, in the IsCrash comment A terminating capture leaves the replay for the next launch and keeps the buffer from switching to session mode; later errors in the same process still send their buffered replay. Co-Authored-By: Claude <noreply@anthropic.com> * Skip reading the native replay id when session replay is off ActiveReplayId on Android and iOS returns null before reading the Java or Cocoa scope when session replay isn't enabled in the options, as CaptureReplay already does. With replay off the native scope never holds a replay id, so this only saves the read on every message and transaction start. Co-Authored-By: Claude <noreply@anthropic.com> * Read the Java scope's replay id through the binding #6016 generates the binding for io.sentry.IScope, so ScopesAdapter exposes Scope, IsolationScope and GlobalScope. That replaces the hand-written JNI lookups, and the ProGuard rules that kept them by name: the .NET build already keeps what managed code calls. The Android device test now puts a replay id on the global scope and checks the read returns it, since a renamed Java method would now fail the build instead. As suggested by @ric-oliv in review. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: James Crosswell <jamescrosswell@users.noreply.github.com>
The Android binding now generates
io.sentry.IScope. With it comeIScopeCallback,IScopeObserver,IFeedbackApiand the getters that return a scope, such asScopesAdapter.Scope,IsolationScopeandGlobalScope. This lets #6001 read the Java scope's replay id through the binding instead of hand-written JNI.The generator used to drop
IScopewithout a visible warning, since the csproj suppresses the BG codes.ISentryClienttakesProfileChunkandProfilingTraceData, whichMetadata.xmlalready removes because they crash the generator. The generator binds an interface whole or not at all, so it droppedISentryClient, and thenIScope, whosegetClient()andbindClient()use it. Removing those twoIScopemembers breaks the chain. Nothing in the SDK calls them.All the new bound types are internal, and nothing uses them yet, so the SDK behaves the same. The binding DLL grows by about 90 KB, or 15 KB gzipped, on each Android target. App builds with the default trim settings don't trim it, so most Android apps carry that too. On an Android emulator, reading the replay id through the new bindings returned the same ids as the JNI code in #6001, with the same allocations.
#skip-changelog