diff --git a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryDependencyContainerTests.h b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryDependencyContainerTests.h index 3b3055e2f3..c987776703 100644 --- a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryDependencyContainerTests.h +++ b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryDependencyContainerTests.h @@ -2,11 +2,6 @@ #import #import -@interface -SentrySDK (PrivateTests) -- (nullable SentryOptions *)options; -@end - @interface SentryDependencyContainer : NSObject + (instancetype)sharedInstance; @property (nonatomic, strong) SentryFramesTracker *framesTracker; diff --git a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryFramesTrackerListenerTests.h b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryFramesTrackerListenerTests.h index 3b3055e2f3..c987776703 100644 --- a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryFramesTrackerListenerTests.h +++ b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryFramesTrackerListenerTests.h @@ -2,11 +2,6 @@ #import #import -@interface -SentrySDK (PrivateTests) -- (nullable SentryOptions *)options; -@end - @interface SentryDependencyContainer : NSObject + (instancetype)sharedInstance; @property (nonatomic, strong) SentryFramesTracker *framesTracker; diff --git a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryTests.h b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryTests.h index 50db4d06c5..fa80410d6c 100644 --- a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryTests.h +++ b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryTests.h @@ -1,8 +1,14 @@ #import #import -@import Sentry; +@class SentryOptions; + +#if CROSS_PLATFORM_TEST +@interface +SentrySDKInternal (PrivateTests) +#else @interface SentrySDK (PrivateTests) -- (nullable SentryOptions *)options; +#endif ++ (nullable SentryOptions *)options; @end diff --git a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryTests.m b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryTests.m index 2b30bb5e1b..2020a8e5a3 100644 --- a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryTests.m +++ b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryTests.m @@ -4,6 +4,7 @@ #import #import #import +@import Sentry; @interface RNSentryInitNativeSdkTests : XCTestCase @@ -464,8 +465,13 @@ - (void)prepareNativeFrameMocksWithLocalSymbolication:(BOOL)debug SentryOptions *sentryOptions = [[SentryOptions alloc] init]; sentryOptions.debug = debug; // no local symbolication +#if CROSS_PLATFORM_TEST + id sentrySDKMock = OCMClassMock([SentrySDKInternal class]); + OCMStub([(Class)sentrySDKMock options]).andReturn(sentryOptions); +#else id sentrySDKMock = OCMClassMock([SentrySDK class]); - OCMStub([(SentrySDK *)sentrySDKMock options]).andReturn(sentryOptions); + OCMStub([(Class)sentrySDKMock options]).andReturn(sentryOptions); +#endif id sentryDependencyContainerMock = OCMClassMock([SentryDependencyContainer class]); OCMStub(ClassMethod([sentryDependencyContainerMock sharedInstance])) diff --git a/packages/core/ios/RNSentry.h b/packages/core/ios/RNSentry.h index cfd0b74b28..9fb651929a 100644 --- a/packages/core/ios/RNSentry.h +++ b/packages/core/ios/RNSentry.h @@ -9,12 +9,18 @@ #import #import -#import typedef int (*SymbolicateCallbackType)(const void *, Dl_info *); +@class SentryOptions; +@class SentryEvent; + +#if CROSS_PLATFORM_TEST +@interface SentrySDKInternal : NSObject +#else @interface SentrySDK (Private) +#endif @property (nonatomic, nullable, readonly, class) SentryOptions *options; @end diff --git a/packages/core/ios/RNSentry.mm b/packages/core/ios/RNSentry.mm index b5fb68aa0d..108631766a 100644 --- a/packages/core/ios/RNSentry.mm +++ b/packages/core/ios/RNSentry.mm @@ -21,9 +21,15 @@ #import #import #import +#import #import +#import #import +#import +#import #import +#import +#import #if __has_include() # define USE_SENTRY_OPTIONS 1 # import @@ -57,15 +63,7 @@ #import "RNSentryExperimentalOptions.h" #import "RNSentryVersion.h" - -@interface -SentrySDK (RNSentry) - -+ (void)captureEnvelope:(SentryEnvelope *)envelope; - -+ (void)storeEnvelope:(SentryEnvelope *)envelope; - -@end +#import "SentrySDKWrapper.h" static bool hasFetchedAppStart; @@ -112,7 +110,7 @@ - (instancetype)init [PrivateSentrySDKOnly addSdkPackage:REACT_NATIVE_SDK_PACKAGE_NAME version:REACT_NATIVE_SDK_PACKAGE_VERSION]; - [SentrySDK startWithOptions:sentryOptions]; + [SentrySDKWrapper startWithOptions:sentryOptions]; #if TARGET_OS_IPHONE || TARGET_OS_MACCATALYST BOOL appIsActive = @@ -363,7 +361,11 @@ - (void)stopObserving - (NSDictionary *)fetchNativeStackFramesBy:(NSArray *)instructionsAddr symbolicate:(SymbolicateCallbackType)symbolicate { +#if CROSS_PLATFORM_TEST + BOOL shouldSymbolicateLocally = [SentrySDKInternal.options debug]; +#else BOOL shouldSymbolicateLocally = [SentrySDK.options debug]; +#endif NSString *appPackageName = [[NSBundle mainBundle] executablePath]; NSMutableSet *_Nonnull imagesAddrToRetrieveDebugMetaImages = @@ -451,7 +453,7 @@ - (NSDictionary *)fetchNativeStackFramesBy:(NSArray *)instructionsAd __block NSMutableDictionary *serializedScope; // Temp work around until sorted out this API in sentry-cocoa. // TODO: If the callback isnt' executed the promise wouldn't be resolved. - [SentrySDK configureScope:^(SentryScope *_Nonnull scope) { + [SentrySDKWrapper configureScope:^(SentryScope *_Nonnull scope) { serializedScope = [[scope serialize] mutableCopy]; NSDictionary *user = [serializedScope valueForKey:@"user"]; @@ -655,7 +657,7 @@ - (NSDictionary *)fetchNativeStackFramesBy:(NSArray *)instructionsAd RCT_EXPORT_METHOD(setUser : (NSDictionary *)userKeys otherUserKeys : (NSDictionary *)userDataKeys) { - [SentrySDK configureScope:^(SentryScope *_Nonnull scope) { + [SentrySDKWrapper configureScope:^(SentryScope *_Nonnull scope) { [scope setUser:[RNSentry userFrom:userKeys otherUserKeys:userDataKeys]]; }]; } @@ -704,7 +706,7 @@ + (SentryUser *_Nullable)userFrom:(NSDictionary *)userKeys RCT_EXPORT_METHOD(addBreadcrumb : (NSDictionary *)breadcrumb) { - [SentrySDK configureScope:^(SentryScope *_Nonnull scope) { + [SentrySDKWrapper configureScope:^(SentryScope *_Nonnull scope) { [scope addBreadcrumb:[RNSentryBreadcrumb from:breadcrumb]]; }]; @@ -718,12 +720,12 @@ + (SentryUser *_Nullable)userFrom:(NSDictionary *)userKeys RCT_EXPORT_METHOD(clearBreadcrumbs) { - [SentrySDK configureScope:^(SentryScope *_Nonnull scope) { [scope clearBreadcrumbs]; }]; + [SentrySDKWrapper configureScope:^(SentryScope *_Nonnull scope) { [scope clearBreadcrumbs]; }]; } RCT_EXPORT_METHOD(setExtra : (NSString *)key extra : (NSString *)extra) { - [SentrySDK + [SentrySDKWrapper configureScope:^(SentryScope *_Nonnull scope) { [scope setExtraValue:extra forKey:key]; }]; } @@ -733,7 +735,7 @@ + (SentryUser *_Nullable)userFrom:(NSDictionary *)userKeys return; } - [SentrySDK configureScope:^(SentryScope *_Nonnull scope) { + [SentrySDKWrapper configureScope:^(SentryScope *_Nonnull scope) { if (context == nil) { [scope removeContextForKey:key]; } else { @@ -744,17 +746,17 @@ + (SentryUser *_Nullable)userFrom:(NSDictionary *)userKeys RCT_EXPORT_METHOD(setTag : (NSString *)key value : (NSString *)value) { - [SentrySDK + [SentrySDKWrapper configureScope:^(SentryScope *_Nonnull scope) { [scope setTagValue:value forKey:key]; }]; } -RCT_EXPORT_METHOD(crash) { [SentrySDK crash]; } +RCT_EXPORT_METHOD(crash) { [SentrySDKWrapper crash]; } RCT_EXPORT_METHOD(closeNativeSdk : (RCTPromiseResolveBlock)resolve rejecter : (RCTPromiseRejectBlock)reject) { - [SentrySDK close]; + [SentrySDKWrapper close]; resolve(@YES); } @@ -957,7 +959,7 @@ + (SentryUser *_Nullable)userFrom:(NSDictionary *)userKeys : (RCTPromiseResolveBlock)resolve rejecter : (RCTPromiseRejectBlock)reject) { - resolve(@([SentrySDK crashedLastRun])); + resolve(@([SentrySDKWrapper crashedLastRun])); } // Thanks to this guard, we won't compile this code when we build for the old architecture. diff --git a/packages/core/ios/RNSentryReplayBreadcrumbConverter.h b/packages/core/ios/RNSentryReplayBreadcrumbConverter.h index 2eee190e26..1a36919a29 100644 --- a/packages/core/ios/RNSentryReplayBreadcrumbConverter.h +++ b/packages/core/ios/RNSentryReplayBreadcrumbConverter.h @@ -1,7 +1,7 @@ @import Sentry; #if SENTRY_TARGET_REPLAY_SUPPORTED -@class SentryRRWebEvent; +@protocol SentryRRWebEvent; @interface RNSentryReplayBreadcrumbConverter : NSObject diff --git a/packages/core/ios/SentrySDKWrapper.h b/packages/core/ios/SentrySDKWrapper.h new file mode 100644 index 0000000000..9040d032ab --- /dev/null +++ b/packages/core/ios/SentrySDKWrapper.h @@ -0,0 +1,18 @@ +#import + +@class SentryOptions; +@class SentryScope; + +@interface SentrySDKWrapper : NSObject + ++ (void)configureScope:(void (^)(SentryScope *scope))callback; + ++ (void)crash; + ++ (void)close; + ++ (BOOL)crashedLastRun; + ++ (void)startWithOptions:(SentryOptions *)options; + +@end diff --git a/packages/core/ios/SentrySDKWrapper.m b/packages/core/ios/SentrySDKWrapper.m new file mode 100644 index 0000000000..0845f1ff3e --- /dev/null +++ b/packages/core/ios/SentrySDKWrapper.m @@ -0,0 +1,31 @@ +#import "SentrySDKWrapper.h" +@import Sentry; + +@implementation SentrySDKWrapper + ++ (void)startWithOptions:(SentryOptions *)options +{ + [SentrySDK startWithOptions:options]; +} + ++ (void)crash +{ + [SentrySDK crash]; +} + ++ (void)close +{ + [SentrySDK close]; +} + ++ (BOOL)crashedLastRun +{ + return [SentrySDK crashedLastRun]; +} + ++ (void)configureScope:(void (^)(SentryScope *scope))callback +{ + [SentrySDK configureScope:callback]; +} + +@end