ref: migrate Cocoa bindings to SentryObjC surface (partial #5444) - #5450
Draft
jamescrosswell wants to merge 3 commits into
Draft
ref: migrate Cocoa bindings to SentryObjC surface (partial #5444)#5450jamescrosswell wants to merge 3 commits into
jamescrosswell wants to merge 3 commits into
Conversation
Rebind the generated Sentry.Bindings.Cocoa surface from the classic Sentry* Objective-C classes to the new SentryObjC* classes (options, SDK entry point, event model, scope, enums, and debug images via [SentryObjCSDK internal].debug). - generate-cocoa-bindings.ps1 now binds the SentryObjC umbrella header only. - patch-cocoa-bindings.cs keeps the SentryObjC* surface the .NET SDK consumes and the public SDK entry points (startWithOptions/configureScope/crash) plus the hybrid `internal` accessor. - Consumers under src/Sentry/Platforms/Cocoa migrated to the SentryObjC* types; debug images now come from the structured internal.debug API. - PrivateApiDefinitions.cs keeps a minimal classic Sentry.framework remnant for the two holdouts that SentryObjC* does not yet expose: scope.applyToEvent enrichment (CocoaEventProcessor) and the SentrySerializable protocol used by envelope serialization. These are the "to be decided" parts of #5444 and are left as-is. This is a partial step: Sentry.xcframework is still shipped, so it does not close the issue. #skip-changelog Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5450 +/- ##
==========================================
+ Coverage 74.62% 74.69% +0.07%
==========================================
Files 512 512
Lines 18672 18722 +50
Branches 3657 3660 +3
==========================================
+ Hits 13934 13985 +51
Misses 3865 3865
+ Partials 873 872 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
|
bless your kind heart for tackling this |
CocoaExtensionsTests and the iOS-conditional SentrySdkTests block referenced the classic Sentry* binding types (SentryEvent, SentryException, SentryBreadcrumb, SentryUser, SentryLevel), which were renamed to SentryObjC* in the rebind. Point them at the SentryObjC* equivalents so the iOS test project compiles. #skip-changelog Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The classic SentryEvent exposed serialize() (via SentrySerializable), which ToSentryEvent used to round-trip a native event into a managed one through JSON. SentryObjCEvent exposes no serialize(), so that path returned null - which made the native beforeSend/event-processor pipeline bail (event dropped, callbacks skipped) and NRE'd the tests that assert on the converted event. Reconstruct the managed SentryEvent directly from the SentryObjCEvent properties instead, mapping the same subset CopyToCocoaSentryEvent writes back plus the exception from the native NSError. Adds ToSentryMessage and a name-correct ToSentryLevelOrNull (SentryObjCLevel has a leading None member, so a direct cast would be off by one). Verified locally against the iOS device test suite (2698 tests, 0 failed), including the four previously-failing CocoaExtensionsTests / SentrySdkTests cases. #skip-changelog Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
jamescrosswell
commented
Jul 29, 2026
Comment on lines
+119
to
+122
| <!-- Workaround for https://github.com/xamarin/xamarin-macios/issues/15299. | ||
| Only runs when bgen actually emits SupportDelegates.g.cs (i.e. when the binding declares | ||
| named delegate types). The SentryObjC surface uses only inline Func/Action callbacks, whose | ||
| trampolines bgen emits as internal delegates in Trampolines.g.cs, so no patching is needed. --> |
Collaborator
Author
There was a problem hiding this comment.
Suggested change
| <!-- Workaround for https://github.com/xamarin/xamarin-macios/issues/15299. | |
| Only runs when bgen actually emits SupportDelegates.g.cs (i.e. when the binding declares | |
| named delegate types). The SentryObjC surface uses only inline Func/Action callbacks, whose | |
| trampolines bgen emits as internal delegates in Trampolines.g.cs, so no patching is needed. --> | |
| <!-- Workaround for https://github.com/xamarin/xamarin-macios/issues/15299. --> |
jamescrosswell
commented
Jul 29, 2026
| return null; | ||
| // Unlike the classic SentryEvent, SentryObjCEvent exposes no serialize() to round-trip through | ||
| // JSON, so we reconstruct the managed event from its properties. We map the same subset that | ||
| // CopyToCocoaSentryEvent writes back, plus the exception derived from the native NSError. |
Collaborator
Author
There was a problem hiding this comment.
I guess there's some symmetry to this (matching CopyToCocoaSentryEvent) so we could go down that route. It would be nicer/easier if we could rely on serialisation to convert events from Cocoa to .NET and back again (we have to maintain the serialisation code to be able to send this stuff to Sentry anyway - so we get .NET <-> Cocoa conversion for free if we do this).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Caution
I think we need to see what shape the new CocoaSDK APIs will take before we can finalise this PR... until we have a solution for
ISentrySerializablein the new APIs, we can't retire the old APIs anyway... so don't really get any benefit from merging until then.Summary
Partial work on #5444 — the mechanical rebind of
Sentry.Bindings.Cocoafrom the classicSentry*Objective-C classes (inSentry.framework) to the newSentryObjC*classes. This is the "mechanical rebind" scoped in the issue's Rebinding section; the two "to be decided" items (scope→event enrichment and the exportedSentrySerializableprotocol) are intentionally left as classic holdouts, so this does not close the issue andSentry.xcframeworkis still shipped.Tip
This looks like a massive commit (and it is) but the bulk of the changes are in the ApiDefinitions.cs file, which is 100% generated code - so not something we need to review in detail (it's validated by the proper building and functioning of the code).
What changed
scripts/generate-cocoa-bindings.ps1— binds theSentryObjC.humbrella header only. It supersedes the classicSentry.h/Sentry-Swift.hsurface as well as the individually-listedSentryObjC*internal headers, and exposes the full public surface (options, SDK entry point, event model, scope, enums) plus the structured hybrid API (SentryObjCSDK.internal, incl. debug images). Framework-style<SentryObjC/…>includes are patched to local quotes for sharpie.scripts/patch-cocoa-bindings.cs— keep-list and per-type rules retargeted to theSentryObjC*names.SentryObjCSDKnow keeps the public entry points the .NET SDK calls (startWithOptions/configureScope/crash/crashedLastRun) alongside theinternalaccessor;SentryObjCInternalApiadditionally keepsdebug. The SentryObjC enums are no longer dropped.ApiDefinitions.cs/StructsAndEnums.cs.PrivateApiDefinitions.cs— replaced the old private-scope partial with a small, self-contained classicSentry.frameworkremnant (SentrySDK.configureScope,SentryScope.applyToEvent,SentryEvent.context, and theSentrySerializableprotocol) for the two holdouts. These classes still ship inSentry.framework(linked alongsideSentryObjC), so the hand-written bindings resolve at runtime.src/Sentry/Platforms/Cocoa/migrated toSentryObjC*. Most of the churn is absorbed by the aliases inSentry.Cocoa.props;CFunctionsnow loads debug images fromSentryObjCSDK.internal.debug.images;CocoaEventProcessorroutes the enrichment holdout through a newSentryCocoaLegacySdkalias.Sentry.Bindings.Cocoa.csproj— theSupportDelegates.g.csinternalizing workaround now only runs when bgen actually emits that file. TheSentryObjCsurface uses inlineFunc/Actioncallbacks (no named delegates), whose trampolines bgen emits asinternaldelegates inTrampolines.g.cs, so there is nothing to patch.Validation
src/Sentry.Bindings.Cocoaandsrc/Sentryboth build fornet9.0-iosandnet9.0-maccatalystlocally (Xcode 26.6, cocoa 9.23.0).Related: #5444
🤖 Generated with Claude Code
#skip-changelog