Repository navigation
feat: support for unity as a library on iOS - #2885
Conversation
|
5e5c48e to
70514de
Compare
…in the host's trace
…IDs skip the bridge call
… unless the game sets its own
…pp's user also applies with SendDefaultPii
…ield against the SDK's defaults
…rt of Unity as a Library
…hecks and keep the typed bridge for bundled exports
…hen it matches the default
| internal string? DefaultRelease { get; } | ||
| internal string DefaultEnvironment { get; } | ||
| // Set through the Editor's overrides, which may match the defaults. | ||
| internal bool ReleaseOverridden { get; set; } | ||
| internal bool EnvironmentOverridden { get; set; } |
There was a problem hiding this comment.
There is an override option in the editor configuration window. And until now the SDK did not need to care where the values were coming from, project settings, overrides, didn't matter as long as we had values. Now that the game wants to take the values from the host we need to check whether these have been explicitly set. Will be picked up with #2914
| [DebuggerStepThrough] | ||
| public static ITransactionTracer StartTransaction(string name, string operation) | ||
| => Sentry.SentrySdk.StartTransaction(name, operation); | ||
| => NativePropagationContext.StartTransaction(Sentry.SentrySdk.CurrentHub, name, operation); |
There was a problem hiding this comment.
This is a workaround for getsentry/sentry-dotnet#5825
The .NET SDK did not expect the ExternalPropagationContext to be used in conjunction with Sentry tracing.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6421df2. Configure here.
…oad phase still on UnityFramework
jpnurmi
left a comment
There was a problem hiding this comment.
A couple of potential findings. Feel free to reject if they're 💩

Adds experimental support for Unity as a Library on iOS: the game runs inside a native app that already uses Sentry, and attaches to that app's sentry-cocoa instead of bundling and starting its own. Part of #2416.
Until now the export always bundled
SentryObjC.xcframeworkand started it from the game. Inside an app that ships its own sentry-cocoa (SPM), that gives two SDKs that fight over the crash handler and the scope, and the game's events come in with the game's release and their own trace.Setup:
options.IosNativeInitializationType = NativeInitializationType.Externalin its options configuration. Using the app's DSN keeps both in one project, so crashes symbolicate with the symbols of both.UnityFrameworktarget, which uploads the game's debug symbols (dSYM, IL2CPP line mappings) when symbol upload is configured.How it works:
Externalnever starts or closes sentry-cocoa. If the app hasn't started it, the game logs a warning and reports C# events only.main.mm. It copies a separate bridge,SentryNativeBridgeExternal.m, that looks up the core classes of the app's SDK (SentrySDKInternal,SentryScope,SentryBreadcrumb) at runtime and checks every selector withrespondsToSelector:, so a missing one is skipped. Regular exports keep the existing bridge: it compiles against the bundledSentryObjCheaders, which an app on plainSentrydoesn't have, and a shared bridge would have lost that compile-time checking for everyone.unity/gpucontexts go to the app's scope. User, environment and trace stay the app's: the game doesn't overwrite them. Sessions and app hangs are left to the app (C# session tracking and the ANR watchdog are off).NativeAppUser). They continue the app's trace through sentry-dotnet'sExternalPropagationContext(NativePropagationContext, read on every use). When the app has an active span, events and outgoing requests carry its baggage. The game's own transactions (startup, scene loads,SentrySdk.StartTransaction(name, op)) become children of the app's active span and inherit its sampling decision; without one they're roots in the app's trace and the game samples.Application.Unloadkeeps the C# SDK alive; reloading doesn't re-init. Theunitycontext stays on the app's scope after unloading.UnityFramework, with the dSYM declared as an input so it exists when the upload runs. AnAppendexport that switches toExternalfails and asks forReplaceinstead of keepingSentryObjClinked.Verified on an iPhone (iOS 27.0.1) at f334634, with
SentryNativeBridgeExternal.m, in a native host app on SPM sentry-cocoa 9.29.0 embeddingunity-of-bugs(Unity 6000.6.6f1, IL2CPP):Debug.LogError, caught and unhandled exceptionsample_rand, transaction)SendDefaultPii)ui.loadtransactionunitycontextForceCrashButtons.cs:6) and the app's frames,unityandgpucontexts, app release, environment, user and traceThe app event before Unity loads, the unhandled exception and
SendDefaultPiiare from the run on the earlier bridge; none of them goes through the bridge.Known limits and follow-ups:
sentry-trace: …-0instead of no decision: sentry-dotnet'sIExternalPropagationContext.IsSampledis abool. Proposed upstream in fix: transactions continue the external propagation context's trace sentry-dotnet#5825 (bool?), then pass it through.SentrySdk.StartTransaction(name, operation[, description])joins the app's trace. Transactions started with aTransactionContextor throughSentry.SentrySdk/IHubstart their own. fix: transactions continue the external propagation context's trace sentry-dotnet#5825 proposes doing this in the hub, which would replace the workaround.SentrySDKInternal,SentryScope.propagationContextTraceHeader,SentryInstallation). If one of them changes, only the feature that uses it is skipped; the rest keeps working. Needs a stable hybrid entry point in sentry-cocoa, also for 10.x.Externalcomes with feat: support for unity as a library on Android #2895 and has to land with this one: on its own,AndroidNativeInitializationType = Externalbehaves likeBuildTime.🤖 Generated with Claude Code