Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
#import <Foundation/Foundation.h>
#import <RNSentry/RNSentry.h>

@interface
SentrySDK (PrivateTests)
- (nullable SentryOptions *)options;
@end

@interface SentryDependencyContainer : NSObject
+ (instancetype)sharedInstance;
@property (nonatomic, strong) SentryFramesTracker *framesTracker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
#import <Foundation/Foundation.h>
#import <RNSentry/RNSentry.h>

@interface
SentrySDK (PrivateTests)
- (nullable SentryOptions *)options;
@end

@interface SentryDependencyContainer : NSObject
+ (instancetype)sharedInstance;
@property (nonatomic, strong) SentryFramesTracker *framesTracker;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#import <Foundation/Foundation.h>
#import <RNSentry/RNSentry.h>
@import Sentry;

@class SentryOptions;

#if CROSS_PLATFORM_TEST
@interface
SentrySDKInternal (PrivateTests)
#else
@interface
SentrySDK (PrivateTests)
- (nullable SentryOptions *)options;
#endif
+ (nullable SentryOptions *)options;
@end
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#import <Sentry/SentryDebugImageProvider+HybridSDKs.h>
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
@import Sentry;

@interface RNSentryInitNativeSdkTests : XCTestCase

Expand Down Expand Up @@ -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]))
Expand Down
8 changes: 7 additions & 1 deletion packages/core/ios/RNSentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@

#import <Sentry/Sentry.h>
#import <Sentry/SentryDebugImageProvider.h>
#import <Sentry/SentryOptions.h>

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

Expand Down
42 changes: 22 additions & 20 deletions packages/core/ios/RNSentry.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@
#import <Sentry/PrivateSentrySDKOnly.h>
#import <Sentry/SentryAppStartMeasurement.h>
#import <Sentry/SentryBinaryImageCache.h>
#import <Sentry/SentryBreadcrumb.h>
#import <Sentry/SentryDebugImageProvider+HybridSDKs.h>
#import <Sentry/SentryDebugMeta.h>
#import <Sentry/SentryDependencyContainer.h>
#import <Sentry/SentryEvent.h>
#import <Sentry/SentryException.h>
#import <Sentry/SentryFormatter.h>
#import <Sentry/SentryOptions.h>
#import <Sentry/SentryUser.h>
#if __has_include(<Sentry/SentryOptions+HybridSDKs.h>)
# define USE_SENTRY_OPTIONS 1
# import <Sentry/SentryOptions+HybridSDKs.h>
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -363,7 +361,11 @@ - (void)stopObserving
- (NSDictionary *)fetchNativeStackFramesBy:(NSArray<NSNumber *> *)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<NSString *> *_Nonnull imagesAddrToRetrieveDebugMetaImages =
Expand Down Expand Up @@ -451,7 +453,7 @@ - (NSDictionary *)fetchNativeStackFramesBy:(NSArray<NSNumber *> *)instructionsAd
__block NSMutableDictionary<NSString *, id> *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<NSString *, id> *user = [serializedScope valueForKey:@"user"];
Expand Down Expand Up @@ -655,7 +657,7 @@ - (NSDictionary *)fetchNativeStackFramesBy:(NSArray<NSNumber *> *)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]];
}];
}
Expand Down Expand Up @@ -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]];
}];

Expand All @@ -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]; }];
}

Expand All @@ -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 {
Expand All @@ -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);
}

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion packages/core/ios/RNSentryReplayBreadcrumbConverter.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@import Sentry;

#if SENTRY_TARGET_REPLAY_SUPPORTED
@class SentryRRWebEvent;
@protocol SentryRRWebEvent;

@interface RNSentryReplayBreadcrumbConverter : NSObject <SentryReplayBreadcrumbConverter>

Expand Down
18 changes: 18 additions & 0 deletions packages/core/ios/SentrySDKWrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#import <Foundation/Foundation.h>

@class SentryOptions;
@class SentryScope;

@interface SentrySDKWrapper : NSObject

+ (void)configureScope:(void (^)(SentryScope *scope))callback;

+ (void)crash;

+ (void)close;

+ (BOOL)crashedLastRun;

+ (void)startWithOptions:(SentryOptions *)options;

@end
31 changes: 31 additions & 0 deletions packages/core/ios/SentrySDKWrapper.m
Original file line number Diff line number Diff line change
@@ -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
Loading