From 2d0f3763fa175d15f922591f5959e94a391eeffd Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Sat, 21 Nov 2026 02:55:55 +0000 Subject: [PATCH] fix(ios): Stop importing SentryScope.h, removed in sentry-cocoa sentry-cocoa converted SentryScope to Swift (getsentry/sentry-cocoa#9552) and deleted Sources/Sentry/Public/SentryScope.h. RNSentryBreadcrumb.h, a public header in the RNSentry umbrella, still imported it, so the module no longer builds against sentry-cocoa main. Drop the unused import. RNSentry.mm then only sees a forward declaration of SentryScope and cannot message it, so route its scope mutations through SentrySDKWrapper, which imports the Sentry module. Co-Authored-By: Itay Brenner --- packages/core/ios/RNSentry.mm | 45 +++++++------------- packages/core/ios/RNSentryBreadcrumb.h | 1 - packages/core/ios/SentrySDKWrapper.h | 25 +++++++++++ packages/core/ios/SentrySDKWrapper.m | 58 ++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 32 deletions(-) diff --git a/packages/core/ios/RNSentry.mm b/packages/core/ios/RNSentry.mm index 55a906648a..6af5b154d2 100644 --- a/packages/core/ios/RNSentry.mm +++ b/packages/core/ios/RNSentry.mm @@ -718,9 +718,7 @@ - (void)handleShakeDetected RCT_EXPORT_METHOD(setUser : (NSDictionary *)userKeys otherUserKeys : (NSDictionary *)userDataKeys) { - [SentrySDKWrapper configureScope:^(SentryScope *_Nonnull scope) { - [scope setUser:[RNSentry userFrom:userKeys otherUserKeys:userDataKeys]]; - }]; + [SentrySDKWrapper setUser:[RNSentry userFrom:userKeys otherUserKeys:userDataKeys]]; } + (SentryUser *_Nullable)userFrom:(NSDictionary *)userKeys @@ -746,9 +744,7 @@ + (SentryUser *_Nullable)userFrom:(NSDictionary *)userKeys RCT_EXPORT_METHOD(addBreadcrumb : (NSDictionary *)breadcrumb) { - [SentrySDKWrapper configureScope:^(SentryScope *_Nonnull scope) { - [scope addBreadcrumb:[RNSentryBreadcrumb from:breadcrumb]]; - }]; + [SentrySDKWrapper addBreadcrumb:[RNSentryBreadcrumb from:breadcrumb]]; #if SENTRY_HAS_UIKIT NSString *_Nullable screen = [RNSentryBreadcrumb getCurrentScreenFrom:breadcrumb]; @@ -758,15 +754,11 @@ + (SentryUser *_Nullable)userFrom:(NSDictionary *)userKeys #endif // SENTRY_HAS_UIKIT } -RCT_EXPORT_METHOD(clearBreadcrumbs) -{ - [SentrySDKWrapper configureScope:^(SentryScope *_Nonnull scope) { [scope clearBreadcrumbs]; }]; -} +RCT_EXPORT_METHOD(clearBreadcrumbs) { [SentrySDKWrapper clearBreadcrumbs]; } RCT_EXPORT_METHOD(setExtra : (NSString *)key extra : (NSString *)extra) { - [SentrySDKWrapper - configureScope:^(SentryScope *_Nonnull scope) { [scope setExtraValue:extra forKey:key]; }]; + [SentrySDKWrapper setExtraValue:extra forKey:key]; } RCT_EXPORT_METHOD(setContext : (NSString *)key context : (NSDictionary *)context) @@ -775,13 +767,11 @@ + (SentryUser *_Nullable)userFrom:(NSDictionary *)userKeys return; } - [SentrySDKWrapper configureScope:^(SentryScope *_Nonnull scope) { - if (context == nil) { - [scope removeContextForKey:key]; - } else { - [scope setContextValue:context forKey:key]; - } - }]; + if (context == nil) { + [SentrySDKWrapper removeContextForKey:key]; + } else { + [SentrySDKWrapper setContextValue:context forKey:key]; + } } RCT_EXPORT_METHOD(removeContext : (NSString *)key) @@ -790,14 +780,12 @@ + (SentryUser *_Nullable)userFrom:(NSDictionary *)userKeys return; } - [SentrySDKWrapper - configureScope:^(SentryScope *_Nonnull scope) { [scope removeContextForKey:key]; }]; + [SentrySDKWrapper removeContextForKey:key]; } RCT_EXPORT_METHOD(setTag : (NSString *)key value : (NSString *)value) { - [SentrySDKWrapper - configureScope:^(SentryScope *_Nonnull scope) { [scope setTagValue:value forKey:key]; }]; + [SentrySDKWrapper setTagValue:value forKey:key]; } RCT_EXPORT_METHOD(addFeatureFlag : (NSString *)name value : (BOOL)value) @@ -807,22 +795,17 @@ + (SentryUser *_Nullable)userFrom:(NSDictionary *)userKeys RCT_EXPORT_METHOD(setAttribute : (NSString *)key value : (NSString *)value) { - [SentrySDKWrapper configureScope:^( - SentryScope *_Nonnull scope) { [scope setAttributeValue:value forKey:key]; }]; + [SentrySDKWrapper setAttributeValue:value forKey:key]; } RCT_EXPORT_METHOD(setAttributes : (NSDictionary *)attributes) { - [SentrySDKWrapper configureScope:^(SentryScope *_Nonnull scope) { - [attributes enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, - BOOL *stop) { [scope setAttributeValue:value forKey:key]; }]; - }]; + [SentrySDKWrapper setAttributes:attributes]; } RCT_EXPORT_METHOD(removeAttribute : (NSString *)key) { - [SentrySDKWrapper - configureScope:^(SentryScope *_Nonnull scope) { [scope removeAttributeForKey:key]; }]; + [SentrySDKWrapper removeAttributeForKey:key]; } RCT_EXPORT_METHOD(crash) { [SentrySDKWrapper crash]; } diff --git a/packages/core/ios/RNSentryBreadcrumb.h b/packages/core/ios/RNSentryBreadcrumb.h index c7ee01dec9..67cb365046 100644 --- a/packages/core/ios/RNSentryBreadcrumb.h +++ b/packages/core/ios/RNSentryBreadcrumb.h @@ -1,6 +1,5 @@ #import #import -#import @class SentryBreadcrumb; diff --git a/packages/core/ios/SentrySDKWrapper.h b/packages/core/ios/SentrySDKWrapper.h index 248f358918..936c5e9261 100644 --- a/packages/core/ios/SentrySDKWrapper.h +++ b/packages/core/ios/SentrySDKWrapper.h @@ -1,12 +1,37 @@ #import +@class SentryBreadcrumb; @class SentryEvent; @class SentryScope; +@class SentryUser; @interface SentrySDKWrapper : NSObject + (void)configureScope:(void (^)(SentryScope *scope))callback; +// Scope mutations for `.mm` callers. sentry-cocoa declares `SentryScope` in Swift, so +// Objective-C++ files only see a forward declaration and cannot message it directly. + ++ (void)setUser:(SentryUser *)user; + ++ (void)addBreadcrumb:(SentryBreadcrumb *)breadcrumb; + ++ (void)clearBreadcrumbs; + ++ (void)setExtraValue:(id)value forKey:(NSString *)key; + ++ (void)setContextValue:(NSDictionary *)value forKey:(NSString *)key; + ++ (void)removeContextForKey:(NSString *)key; + ++ (void)setTagValue:(NSString *)value forKey:(NSString *)key; + ++ (void)setAttributeValue:(id)value forKey:(NSString *)key; + ++ (void)setAttributes:(NSDictionary *)attributes; + ++ (void)removeAttributeForKey:(NSString *)key; + + (void)captureEvent:(SentryEvent *)event; + (void)crash; diff --git a/packages/core/ios/SentrySDKWrapper.m b/packages/core/ios/SentrySDKWrapper.m index 9095f4bb8c..11f778abea 100644 --- a/packages/core/ios/SentrySDKWrapper.m +++ b/packages/core/ios/SentrySDKWrapper.m @@ -54,6 +54,64 @@ + (void)configureScope:(void (^)(SentryScope *scope))callback [SentrySDK configureScope:callback]; } ++ (void)setUser:(SentryUser *)user +{ + [SentrySDK configureScope:^(SentryScope *_Nonnull scope) { [scope setUser:user]; }]; +} + ++ (void)addBreadcrumb:(SentryBreadcrumb *)breadcrumb +{ + [SentrySDK configureScope:^(SentryScope *_Nonnull scope) { [scope addBreadcrumb:breadcrumb]; }]; +} + ++ (void)clearBreadcrumbs +{ + [SentrySDK configureScope:^(SentryScope *_Nonnull scope) { [scope clearBreadcrumbs]; }]; +} + ++ (void)setExtraValue:(id)value forKey:(NSString *)key +{ + [SentrySDK + configureScope:^(SentryScope *_Nonnull scope) { [scope setExtraValue:value forKey:key]; }]; +} + ++ (void)setContextValue:(NSDictionary *)value forKey:(NSString *)key +{ + [SentrySDK configureScope:^( + SentryScope *_Nonnull scope) { [scope setContextValue:value forKey:key]; }]; +} + ++ (void)removeContextForKey:(NSString *)key +{ + [SentrySDK configureScope:^(SentryScope *_Nonnull scope) { [scope removeContextForKey:key]; }]; +} + ++ (void)setTagValue:(NSString *)value forKey:(NSString *)key +{ + [SentrySDK + configureScope:^(SentryScope *_Nonnull scope) { [scope setTagValue:value forKey:key]; }]; +} + ++ (void)setAttributeValue:(id)value forKey:(NSString *)key +{ + [SentrySDK configureScope:^( + SentryScope *_Nonnull scope) { [scope setAttributeValue:value forKey:key]; }]; +} + ++ (void)setAttributes:(NSDictionary *)attributes +{ + [SentrySDK configureScope:^(SentryScope *_Nonnull scope) { + [attributes enumerateKeysAndObjectsUsingBlock:^( + NSString *key, id value, BOOL *stop) { [scope setAttributeValue:value forKey:key]; }]; + }]; +} + ++ (void)removeAttributeForKey:(NSString *)key +{ + [SentrySDK + configureScope:^(SentryScope *_Nonnull scope) { [scope removeAttributeForKey:key]; }]; +} + + (BOOL)debug { return RNSentryInternal.options.debug;