Skip to content

Commit af6a6d6

Browse files
authored
fix: pass failed request codes down to cocoa (#2619)
1 parent e3c20dc commit af6a6d6

5 files changed

Lines changed: 45 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Fixes
66

7+
- When targeting iOS or macOS, the SDK now correctly passes on the `CaptureFailedRequests` flag and set status code ranged ([#2619](https://github.com/getsentry/sentry-unity/pull/2619))
78
- The SDK now correctly resolves the storage path on Xbox during initialization, enabling offline caching and native crash capturing without user setup out of the box. ([#2617](https://github.com/getsentry/sentry-unity/pull/2617))
89

910
### Features

package-dev/Plugins/iOS/SentryNativeBridge.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ void SentryNativeBridgeOptionsSetInt(const void *options, const char *name, int3
6666
dictOptions[[NSString stringWithUTF8String:name]] = [NSNumber numberWithInt:value];
6767
}
6868

69+
void SentryNativeBridgeOptionsAddFailedRequestStatusCodeRange(const void *options, int32_t min, int32_t max)
70+
{
71+
NSMutableDictionary *dictOptions = (__bridge NSMutableDictionary *)options;
72+
NSMutableArray *ranges = dictOptions[@"failedRequestStatusCodes"];
73+
if (!ranges) {
74+
ranges = [[NSMutableArray alloc] init];
75+
dictOptions[@"failedRequestStatusCodes"] = ranges;
76+
}
77+
[ranges addObject:[[SentryHttpStatusCodeRange alloc] initWithMin:min max:max]];
78+
}
79+
6980
int SentryNativeBridgeStartWithOptions(const void *options)
7081
{
7182
NSMutableDictionary *dictOptions = (__bridge_transfer NSMutableDictionary *)options;

package-dev/Plugins/iOS/SentryNativeBridgeNoOp.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
void *_Nullable SentryNativeBridgeOptionsNew() { return nil; }
77
void SentryNativeBridgeOptionsSetString(void *options, const char *name, const char *value) { }
88
void SentryNativeBridgeOptionsSetInt(void *options, const char *name, int32_t value) { }
9+
void SentryNativeBridgeOptionsAddFailedRequestStatusCodeRange(void *options, int32_t min, int32_t max) { }
910
int SentryNativeBridgeStartWithOptions(void *options) { return 0; }
1011

1112
void SentryNativeBridgeSetSdkName() { }

package-dev/Plugins/macOS/SentryNativeBridge.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#import <Foundation/Foundation.h>
22
#include <dlfcn.h>
3+
#include <objc/message.h>
34

45
static NSDateFormatter *_Nullable sentry_cachedISO8601Formatter(void) {
56
static NSDateFormatter *formatter = nil;
@@ -45,6 +46,7 @@
4546
static Class SentryId;
4647
static Class SentrySpanId;
4748
static Class PrivateSentrySDKOnly;
49+
static Class SentryHttpStatusCodeRange;
4850

4951
#define LOAD_CLASS_OR_BREAK(name) \
5052
name = (__bridge Class)dlsym(dylib, "OBJC_CLASS_$_" #name); \
@@ -87,6 +89,7 @@ int SentryNativeBridgeLoadLibrary()
8789
LOAD_CLASS_OR_BREAK(SentryId)
8890
LOAD_CLASS_OR_BREAK(SentrySpanId)
8991
LOAD_CLASS_OR_BREAK(PrivateSentrySDKOnly)
92+
LOAD_CLASS_OR_BREAK(SentryHttpStatusCodeRange)
9093

9194
// everything above passed - mark as successfully loaded
9295
loadStatus = 1;
@@ -118,6 +121,23 @@ void SentryNativeBridgeOptionsSetInt(const void *options, const char *name, int3
118121
dictOptions[[NSString stringWithUTF8String:name]] = [NSNumber numberWithInt:value];
119122
}
120123

124+
void SentryNativeBridgeOptionsAddFailedRequestStatusCodeRange(const void *options, int32_t min, int32_t max)
125+
{
126+
NSMutableDictionary *dictOptions = (__bridge NSMutableDictionary *)options;
127+
NSMutableArray *ranges = dictOptions[@"failedRequestStatusCodes"];
128+
if (!ranges) {
129+
ranges = [[NSMutableArray alloc] init];
130+
dictOptions[@"failedRequestStatusCodes"] = ranges;
131+
}
132+
id instance = [SentryHttpStatusCodeRange alloc];
133+
// initWithMin:max: takes NSInteger args - use objc_msgSend directly
134+
id range = ((id (*)(id, SEL, NSInteger, NSInteger))objc_msgSend)(
135+
instance, @selector(initWithMin:max:), (NSInteger)min, (NSInteger)max);
136+
if (range) {
137+
[ranges addObject:range];
138+
}
139+
}
140+
121141
int SentryNativeBridgeStartWithOptions(const void *options)
122142
{
123143
NSMutableDictionary *dictOptions = (__bridge_transfer NSMutableDictionary *)options;

src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ public static bool Init(SentryUnityOptions options)
6969
Logger?.LogDebug("Setting EnableWatchdogTerminationTracking: {0}", options.IosWatchdogTerminationIntegrationEnabled);
7070
OptionsSetInt(cOptions, "enableWatchdogTerminationTracking", options.IosWatchdogTerminationIntegrationEnabled ? 1 : 0);
7171

72+
Logger?.LogDebug("Setting CaptureFailedRequests: {0}", options.CaptureFailedRequests);
73+
OptionsSetInt(cOptions, "enableCaptureFailedRequests", options.CaptureFailedRequests ? 1 : 0);
74+
75+
foreach (var range in options.FailedRequestStatusCodes)
76+
{
77+
Logger?.LogDebug("Adding FailedRequestStatusCodeRange: {0}-{1}", range.Start, range.End);
78+
OptionsAddFailedRequestStatusCodeRange(cOptions, range.Start, range.End);
79+
}
80+
7281
var result = StartWithOptions(cOptions);
7382
return result is 1;
7483
}
@@ -88,6 +97,9 @@ public static bool Init(SentryUnityOptions options)
8897
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeOptionsSetInt")]
8998
private static extern void OptionsSetInt(IntPtr options, string name, int value);
9099

100+
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeOptionsAddFailedRequestStatusCodeRange")]
101+
private static extern void OptionsAddFailedRequestStatusCodeRange(IntPtr options, int min, int max);
102+
91103
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeStartWithOptions")]
92104
private static extern int StartWithOptions(IntPtr options);
93105

0 commit comments

Comments
 (0)