Skip to content

Commit 8a254be

Browse files
committed
Support sentry SDK Swift
1 parent 466115d commit 8a254be

5 files changed

Lines changed: 56 additions & 30 deletions

File tree

packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryDependencyContainerTests.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
#import <Foundation/Foundation.h>
33
#import <RNSentry/RNSentry.h>
44

5-
@interface
6-
SentrySDK (PrivateTests)
7-
- (nullable SentryOptions *)options;
8-
@end
9-
105
@interface SentryDependencyContainer : NSObject
116
+ (instancetype)sharedInstance;
127
@property (nonatomic, strong) SentryFramesTracker *framesTracker;

packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryFramesTrackerListenerTests.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
#import <Foundation/Foundation.h>
33
#import <RNSentry/RNSentry.h>
44

5-
@interface
6-
SentrySDK (PrivateTests)
7-
- (nullable SentryOptions *)options;
8-
@end
9-
105
@interface SentryDependencyContainer : NSObject
116
+ (instancetype)sharedInstance;
127
@property (nonatomic, strong) SentryFramesTracker *framesTracker;

packages/core/ios/RNSentry.mm

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,7 @@
5757

5858
#import "RNSentryExperimentalOptions.h"
5959
#import "RNSentryVersion.h"
60-
61-
@interface
62-
SentrySDK (RNSentry)
63-
64-
+ (void)captureEnvelope:(SentryEnvelope *)envelope;
65-
66-
+ (void)storeEnvelope:(SentryEnvelope *)envelope;
67-
68-
@end
60+
#import "SentrySDKWrapper.h"
6961

7062
static bool hasFetchedAppStart;
7163

@@ -112,7 +104,7 @@ - (instancetype)init
112104
[PrivateSentrySDKOnly addSdkPackage:REACT_NATIVE_SDK_PACKAGE_NAME
113105
version:REACT_NATIVE_SDK_PACKAGE_VERSION];
114106

115-
[SentrySDK startWithOptions:sentryOptions];
107+
[SentrySDKWrapper startWithOptions:sentryOptions];
116108

117109
#if TARGET_OS_IPHONE || TARGET_OS_MACCATALYST
118110
BOOL appIsActive =
@@ -451,7 +443,7 @@ - (NSDictionary *)fetchNativeStackFramesBy:(NSArray<NSNumber *> *)instructionsAd
451443
__block NSMutableDictionary<NSString *, id> *serializedScope;
452444
// Temp work around until sorted out this API in sentry-cocoa.
453445
// TODO: If the callback isnt' executed the promise wouldn't be resolved.
454-
[SentrySDK configureScope:^(SentryScope *_Nonnull scope) {
446+
[SentrySDKWrapper configureScope:^(SentryScope *_Nonnull scope) {
455447
serializedScope = [[scope serialize] mutableCopy];
456448

457449
NSDictionary<NSString *, id> *user = [serializedScope valueForKey:@"user"];
@@ -655,7 +647,7 @@ - (NSDictionary *)fetchNativeStackFramesBy:(NSArray<NSNumber *> *)instructionsAd
655647

656648
RCT_EXPORT_METHOD(setUser : (NSDictionary *)userKeys otherUserKeys : (NSDictionary *)userDataKeys)
657649
{
658-
[SentrySDK configureScope:^(SentryScope *_Nonnull scope) {
650+
[SentrySDKWrapper configureScope:^(SentryScope *_Nonnull scope) {
659651
[scope setUser:[RNSentry userFrom:userKeys otherUserKeys:userDataKeys]];
660652
}];
661653
}
@@ -704,7 +696,7 @@ + (SentryUser *_Nullable)userFrom:(NSDictionary *)userKeys
704696

705697
RCT_EXPORT_METHOD(addBreadcrumb : (NSDictionary *)breadcrumb)
706698
{
707-
[SentrySDK configureScope:^(SentryScope *_Nonnull scope) {
699+
[SentrySDKWrapper configureScope:^(SentryScope *_Nonnull scope) {
708700
[scope addBreadcrumb:[RNSentryBreadcrumb from:breadcrumb]];
709701
}];
710702

@@ -718,12 +710,12 @@ + (SentryUser *_Nullable)userFrom:(NSDictionary *)userKeys
718710

719711
RCT_EXPORT_METHOD(clearBreadcrumbs)
720712
{
721-
[SentrySDK configureScope:^(SentryScope *_Nonnull scope) { [scope clearBreadcrumbs]; }];
713+
[SentrySDKWrapper configureScope:^(SentryScope *_Nonnull scope) { [scope clearBreadcrumbs]; }];
722714
}
723715

724716
RCT_EXPORT_METHOD(setExtra : (NSString *)key extra : (NSString *)extra)
725717
{
726-
[SentrySDK
718+
[SentrySDKWrapper
727719
configureScope:^(SentryScope *_Nonnull scope) { [scope setExtraValue:extra forKey:key]; }];
728720
}
729721

@@ -733,7 +725,7 @@ + (SentryUser *_Nullable)userFrom:(NSDictionary *)userKeys
733725
return;
734726
}
735727

736-
[SentrySDK configureScope:^(SentryScope *_Nonnull scope) {
728+
[SentrySDKWrapper configureScope:^(SentryScope *_Nonnull scope) {
737729
if (context == nil) {
738730
[scope removeContextForKey:key];
739731
} else {
@@ -744,17 +736,17 @@ + (SentryUser *_Nullable)userFrom:(NSDictionary *)userKeys
744736

745737
RCT_EXPORT_METHOD(setTag : (NSString *)key value : (NSString *)value)
746738
{
747-
[SentrySDK
739+
[SentrySDKWrapper
748740
configureScope:^(SentryScope *_Nonnull scope) { [scope setTagValue:value forKey:key]; }];
749741
}
750742

751-
RCT_EXPORT_METHOD(crash) { [SentrySDK crash]; }
743+
RCT_EXPORT_METHOD(crash) { [SentrySDKWrapper crash]; }
752744

753745
RCT_EXPORT_METHOD(closeNativeSdk
754746
: (RCTPromiseResolveBlock)resolve rejecter
755747
: (RCTPromiseRejectBlock)reject)
756748
{
757-
[SentrySDK close];
749+
[SentrySDKWrapper close];
758750
resolve(@YES);
759751
}
760752

@@ -957,7 +949,7 @@ + (SentryUser *_Nullable)userFrom:(NSDictionary *)userKeys
957949
: (RCTPromiseResolveBlock)resolve rejecter
958950
: (RCTPromiseRejectBlock)reject)
959951
{
960-
resolve(@([SentrySDK crashedLastRun]));
952+
resolve(@([SentrySDKWrapper crashedLastRun]));
961953
}
962954

963955
// Thanks to this guard, we won't compile this code when we build for the old architecture.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#import <Foundation/Foundation.h>
2+
3+
@class SentryOptions;
4+
@class SentryScope;
5+
6+
@interface SentrySDKWrapper : NSObject
7+
8+
+ (void)configureScope:(void (^)(SentryScope *scope))callback;
9+
10+
+ (void)crash;
11+
12+
+ (void)close;
13+
14+
+(BOOL)crashedLastRun;
15+
16+
+ (void)startWithOptions:(SentryOptions *)options;
17+
18+
@end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#import "SentrySDKWrapper.h"
2+
@import Sentry;
3+
4+
@implementation SentrySDKWrapper
5+
6+
+ (void)startWithOptions:(SentryOptions *)options {
7+
[SentrySDK startWithOptions:options];
8+
}
9+
10+
+ (void)crash {
11+
[SentrySDK crash];
12+
}
13+
14+
+ (void)close {
15+
[SentrySDK close];
16+
}
17+
18+
+ (BOOL)crashedLastRun {
19+
return [SentrySDK crashedLastRun];
20+
}
21+
22+
+ (void)configureScope:(void (^)(SentryScope *scope))callback {
23+
[SentrySDK configureScope:callback];
24+
}
25+
26+
@end

0 commit comments

Comments
 (0)