Skip to content

Commit e3e75a9

Browse files
authored
fix: Reporting SDK's name on Apple platforms (#2112)
* return success state * Updated CHANGELOG.md * set sdk name * native options use bridge. and tests * native options set name * evil '' * fixed test
1 parent f0e68a5 commit e3e75a9

File tree

6 files changed

+32
-0
lines changed

6 files changed

+32
-0
lines changed

package-dev/Plugins/iOS/SentryNativeBridge.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ int SentryNativeBridgeStartWithOptions(const void *options)
4646
return 1;
4747
}
4848

49+
void SentryNativeBridgeSetSdkName()
50+
{
51+
[PrivateSentrySDKOnly performSelector:@selector(setSdkName:) withObject:@"sentry.cocoa.unity"];
52+
}
53+
4954
int SentryNativeBridgeCrashedLastRun() { return [SentrySDK crashedLastRun] ? 1 : 0; }
5055

5156
void SentryNativeBridgeClose() { [SentrySDK close]; }

package-dev/Plugins/iOS/SentryNativeBridgeNoOp.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ void SentryNativeBridgeOptionsSetString(void *options, const char *name, const c
88
void SentryNativeBridgeOptionsSetInt(void *options, const char *name, int32_t value) { }
99
int SentryNativeBridgeStartWithOptions(void *options) { return 0; }
1010

11+
void SentryNativeBridgeSetSdkName() { }
12+
1113
int SentryNativeBridgeCrashedLastRun() { return 0; }
1214

1315
void SentryNativeBridgeClose() { }

package-dev/Plugins/macOS/SentryNativeBridge.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ void SentryConfigureScope(void (^callback)(id))
123123
/* - use [obj setValue:value forKey:@"prop"] instead of `obj.prop = value` */
124124
/*******************************************************************************/
125125

126+
void SentryNativeBridgeSetSdkName()
127+
{
128+
[PrivateSentrySDKOnly performSelector:@selector(setSdkName:) withObject:@"sentry.cocoa.unity"];
129+
}
130+
126131
int SentryNativeBridgeCrashedLastRun()
127132
{
128133
@try {

src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public static bool Init(SentryUnityOptions options)
8282
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeStartWithOptions")]
8383
private static extern int StartWithOptions(IntPtr options);
8484

85+
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeSetSdkName")]
86+
public static extern int SetSdkName();
87+
8588
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeCrashedLastRun")]
8689
public static extern int CrashedLastRun();
8790

src/Sentry.Unity.iOS/SentryNativeCocoa.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ internal static void Configure(SentryUnityOptions options, ISentryUnityInfo sent
5252
options.ScopeObserver = new NativeScopeObserver("macOS", options);
5353
}
5454

55+
SentryCocoaBridgeProxy.SetSdkName(); // Since we're not building the SDK we have to overwrite the name here
56+
5557
options.NativeContextWriter = new NativeContextWriter();
5658
options.EnableScopeSync = true;
5759
options.CrashedLastRun = () =>

test/Sentry.Unity.Editor.iOS.Tests/NativeOptionsTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@ public void CreateOptionsFile_NewSentryOptions_ContainsBaseOptions()
8787
File.Delete(testOptionsFileName);
8888
}
8989

90+
[Test]
91+
public void CreateOptionsFile_NewSentryOptions_ContainsSdkNameSetting()
92+
{
93+
const string testOptionsFileName = "testOptions.m";
94+
95+
NativeOptions.CreateFile(testOptionsFileName, new SentryUnityOptions());
96+
97+
Assert.IsTrue(File.Exists(testOptionsFileName)); // Sanity check
98+
99+
var nativeOptions = File.ReadAllText(testOptionsFileName);
100+
StringAssert.Contains("sentry.cocoa.unity", nativeOptions);
101+
102+
File.Delete(testOptionsFileName);
103+
}
104+
90105
[Test]
91106
public void CreateOptionsFile_FilterBadGatewayEnabled_AddsFiltering()
92107
{

0 commit comments

Comments
 (0)