diff --git a/package-dev/Plugins/iOS/SentryNativeBridge.m b/package-dev/Plugins/iOS/SentryNativeBridge.m index 98982997d..fb749675c 100644 --- a/package-dev/Plugins/iOS/SentryNativeBridge.m +++ b/package-dev/Plugins/iOS/SentryNativeBridge.m @@ -46,6 +46,11 @@ int SentryNativeBridgeStartWithOptions(const void *options) return 1; } +void SentryNativeBridgeSetSdkName() +{ + [PrivateSentrySDKOnly performSelector:@selector(setSdkName:) withObject:@"sentry.cocoa.unity"]; +} + int SentryNativeBridgeCrashedLastRun() { return [SentrySDK crashedLastRun] ? 1 : 0; } void SentryNativeBridgeClose() { [SentrySDK close]; } diff --git a/package-dev/Plugins/iOS/SentryNativeBridgeNoOp.m b/package-dev/Plugins/iOS/SentryNativeBridgeNoOp.m index e9688495f..be9cf62d6 100644 --- a/package-dev/Plugins/iOS/SentryNativeBridgeNoOp.m +++ b/package-dev/Plugins/iOS/SentryNativeBridgeNoOp.m @@ -8,6 +8,8 @@ void SentryNativeBridgeOptionsSetString(void *options, const char *name, const c void SentryNativeBridgeOptionsSetInt(void *options, const char *name, int32_t value) { } int SentryNativeBridgeStartWithOptions(void *options) { return 0; } +void SentryNativeBridgeSetSdkName() { } + int SentryNativeBridgeCrashedLastRun() { return 0; } void SentryNativeBridgeClose() { } diff --git a/package-dev/Plugins/macOS/SentryNativeBridge.m b/package-dev/Plugins/macOS/SentryNativeBridge.m index 9deca8dae..d80f6f7b3 100644 --- a/package-dev/Plugins/macOS/SentryNativeBridge.m +++ b/package-dev/Plugins/macOS/SentryNativeBridge.m @@ -112,6 +112,11 @@ void SentryConfigureScope(void (^callback)(id)) /* - use [obj setValue:value forKey:@"prop"] instead of `obj.prop = value` */ /*******************************************************************************/ +void SentryNativeBridgeSetSdkName() +{ + [PrivateSentrySDKOnly performSelector:@selector(setSdkName:) withObject:@"sentry.cocoa.unity"]; +} + int SentryNativeBridgeCrashedLastRun() { @try { diff --git a/src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs b/src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs index 7c8442c98..9637d3865 100644 --- a/src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs +++ b/src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs @@ -82,6 +82,9 @@ public static bool Init(SentryUnityOptions options) [DllImport("__Internal", EntryPoint = "SentryNativeBridgeStartWithOptions")] private static extern int StartWithOptions(IntPtr options); + [DllImport("__Internal", EntryPoint = "SentryNativeBridgeSetSdkName")] + public static extern int SetSdkName(); + [DllImport("__Internal", EntryPoint = "SentryNativeBridgeCrashedLastRun")] public static extern int CrashedLastRun(); diff --git a/src/Sentry.Unity.iOS/SentryNativeCocoa.cs b/src/Sentry.Unity.iOS/SentryNativeCocoa.cs index 9d2097d3e..766fe5a55 100644 --- a/src/Sentry.Unity.iOS/SentryNativeCocoa.cs +++ b/src/Sentry.Unity.iOS/SentryNativeCocoa.cs @@ -52,6 +52,8 @@ internal static void Configure(SentryUnityOptions options, ISentryUnityInfo sent options.ScopeObserver = new NativeScopeObserver("macOS", options); } + SentryCocoaBridgeProxy.SetSdkName(); // Since we're not building the SDK we have to overwrite the name here + options.NativeContextWriter = new NativeContextWriter(); options.EnableScopeSync = true; options.CrashedLastRun = () => diff --git a/test/Sentry.Unity.Editor.iOS.Tests/NativeOptionsTests.cs b/test/Sentry.Unity.Editor.iOS.Tests/NativeOptionsTests.cs index 21feb313c..814bd017b 100644 --- a/test/Sentry.Unity.Editor.iOS.Tests/NativeOptionsTests.cs +++ b/test/Sentry.Unity.Editor.iOS.Tests/NativeOptionsTests.cs @@ -87,6 +87,21 @@ public void CreateOptionsFile_NewSentryOptions_ContainsBaseOptions() File.Delete(testOptionsFileName); } + [Test] + public void CreateOptionsFile_NewSentryOptions_ContainsSdkNameSetting() + { + const string testOptionsFileName = "testOptions.m"; + + NativeOptions.CreateFile(testOptionsFileName, new SentryUnityOptions()); + + Assert.IsTrue(File.Exists(testOptionsFileName)); // Sanity check + + var nativeOptions = File.ReadAllText(testOptionsFileName); + StringAssert.Contains("sentry.cocoa.unity", nativeOptions); + + File.Delete(testOptionsFileName); + } + [Test] public void CreateOptionsFile_FilterBadGatewayEnabled_AddsFiltering() {