Skip to content

Migrate from PrivateSentrySDKOnly to SentryObjCSDK.internal #2742

Description

@philprime

sentry-cocoa 9.19.0 introduces a new structured hybrid SDK API via SentrySDK.internal (Swift) and SentryObjCSDK.internal (ObjC). The old PrivateSentrySDKOnly class is deprecated and will be removed in the next major version.

Implementation PR: getsentry/sentry-cocoa#8097
Design doc: SENTRY-INTERNAL-API.md

Benefits

  • Eliminates 3 internal header imports. Drop PrivateSentrySDKOnly.h, SentryOptionsInternal.h, and Sentry-Swift.h. The new API is fully public via <SentryObjC/SentryObjC.h>.
  • No more NSClassFromString / performSelector: hacks. Unity previously used NSClassFromString(@"SentryId") as a workaround for SentryId living in the Swift bridging header. The new ObjC API provides SentryObjCId and SentryObjCSpanId as proper ObjC types.
  • No more SentryOptionsInternal.h. The +initWithDict:didFailWithError: method is now [[SentryObjCSDK internal] optionsFromDictionary:error:].
  • SPM / xcframework compatible. Works with binary distribution — no exposed private headers.

Import Change

iOS (Plugins/iOS/SentryNativeBridge.m)

// Before
#import <Sentry/Sentry-Swift.h>
#import <Sentry/PrivateSentrySDKOnly.h>
#import <Sentry/SentryOptionsInternal.h>

// After — single import, no internal headers
#import <SentryObjC/SentryObjC.h>

macOS (Plugins/macOS/SentryNativeBridge.m)

The macOS bridge currently loads classes dynamically via NSClassFromString:

// Before
static Class SentryOptionsInternal;
static Class PrivateSentrySDKOnly;
LOAD_CLASS_OR_BREAK(SentryOptionsInternal)
LOAD_CLASS_OR_BREAK(PrivateSentrySDKOnly)

// After — direct import, no dynamic loading needed
#import <SentryObjC/SentryObjC.h>
// Use [SentryObjCSDK internal].* directly

Key Changes

  • [SentryOptionsInternal initWithDict:dict didFailWithError:&error][[SentryObjCSDK internal] optionsFromDictionary:dict error:&error]
  • [PrivateSentrySDKOnly setSdkName:@"sentry.cocoa.unity"][SentryObjCSDK internal].sdk.name = @"sentry.cocoa.unity"
  • [PrivateSentrySDKOnly installationID][SentryObjCSDK internal].sdk.installationID
  • [PrivateSentrySDKOnly setTrace:traceId spanId:spanId][[SentryObjCSDK internal] setTrace:traceId spanId:spanId]
  • [PrivateSentrySDKOnly captureEnvelope:envelope][[[SentryObjCSDK internal] envelope] capture:envelope]
  • NSClassFromString(@"SentryId")SentryObjCId (proper ObjC type)
  • NSClassFromString(@"SentrySpanId")SentryObjCSpanId (proper ObjC type)

Affected Files (as of latest main)

  • package-dev/Plugins/iOS/SentryNativeBridge.m — direct imports + call sites
  • package-dev/Plugins/macOS/SentryNativeBridge.m — dynamic class loading + performSelector:
  • src/Sentry.Unity.Editor.iOS/NativeOptions.cs — C# code gen emitting ObjC
  • src/Sentry.Unity.Editor.iOS/NativeMain.cs — C# code gen emitting import

Checklist

  • Replace all PrivateSentrySDKOnly / SentryOptionsInternal call sites with [SentryObjCSDK internal].*
  • Remove Sentry-Swift.h import — use SentryObjCId / SentryObjCSpanId instead
  • Remove dynamic class loading (NSClassFromString) for SentryOptionsInternal and PrivateSentrySDKOnly on macOS
  • Update C# code generators (NativeOptions.cs, NativeMain.cs) to emit new ObjC API
  • Change all imports to #import <SentryObjC/SentryObjC.h>
  • Bump minimum sentry-cocoa dependency to 9.19.0+
  • Run full test suite to verify no regressions

Metadata

Metadata

Assignees

Labels

Improvementimprovement for existing featuresUnityplatform label

Fields

No fields configured for issues without a type.

Projects

Status
No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions