diff --git a/packages/core/RNSentryCocoaTester/RNSentryCocoaTester.xcodeproj/project.pbxproj b/packages/core/RNSentryCocoaTester/RNSentryCocoaTester.xcodeproj/project.pbxproj index 02284f6023..1645b60166 100644 --- a/packages/core/RNSentryCocoaTester/RNSentryCocoaTester.xcodeproj/project.pbxproj +++ b/packages/core/RNSentryCocoaTester/RNSentryCocoaTester.xcodeproj/project.pbxproj @@ -40,9 +40,7 @@ 338739072A7D7D2800950DDD /* RNSentryReplay.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNSentryReplay.h; path = ../ios/RNSentryReplay.h; sourceTree = ""; }; 33958C672BFCEF5A00AD1FB6 /* RNSentryOnDrawReporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSentryOnDrawReporter.h; path = ../ios/RNSentryOnDrawReporter.h; sourceTree = ""; }; 33AFDFEC2B8D14B300AAB120 /* RNSentryFramesTrackerListenerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNSentryFramesTrackerListenerTests.m; sourceTree = ""; }; - 33AFDFEE2B8D14C200AAB120 /* RNSentryFramesTrackerListenerTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNSentryFramesTrackerListenerTests.h; sourceTree = ""; }; 33AFDFF02B8D15E500AAB120 /* RNSentryDependencyContainerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNSentryDependencyContainerTests.m; sourceTree = ""; }; - 33AFDFF22B8D15F600AAB120 /* RNSentryDependencyContainerTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNSentryDependencyContainerTests.h; sourceTree = ""; }; 33AFE0132B8F31AF00AAB120 /* RNSentryDependencyContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSentryDependencyContainer.h; path = ../ios/RNSentryDependencyContainer.h; sourceTree = ""; }; 33DEDFE92D8DBE5B006066E4 /* RNSentryOnDrawReporterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNSentryOnDrawReporterTests.swift; sourceTree = ""; }; 33DEDFEB2D8DC800006066E4 /* RNSentryOnDrawReporter+Test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNSentryOnDrawReporter+Test.h"; sourceTree = ""; }; @@ -52,6 +50,9 @@ 33F58ACF2977037D008F60EA /* RNSentryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSentryTests.m; sourceTree = ""; }; 650CB718ACFBD05609BF2126 /* libPods-RNSentryCocoaTesterTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-RNSentryCocoaTesterTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; E2321E7CFA55AB617247098E /* Pods-RNSentryCocoaTesterTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNSentryCocoaTesterTests.debug.xcconfig"; path = "Target Support Files/Pods-RNSentryCocoaTesterTests/Pods-RNSentryCocoaTesterTests.debug.xcconfig"; sourceTree = ""; }; + F48F26542EA2A481008A185E /* RNSentryEmitNewFrameEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNSentryEmitNewFrameEvent.h; path = ../ios/RNSentryEmitNewFrameEvent.h; sourceTree = SOURCE_ROOT; }; + FADF868E2EBD053E00D6652D /* SentrySDKWrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentrySDKWrapper.h; path = ../ios/SentrySDKWrapper.h; sourceTree = SOURCE_ROOT; }; + F48F26552EA2A4D4008A185E /* RNSentryFramesTrackerListener.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNSentryFramesTrackerListener.h; path = ../ios/RNSentryFramesTrackerListener.h; sourceTree = SOURCE_ROOT; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -108,9 +109,7 @@ 33F58ACF2977037D008F60EA /* RNSentryTests.m */, 3339C4802D6625570088EB3A /* RNSentryUserTests.m */, 33AFDFEC2B8D14B300AAB120 /* RNSentryFramesTrackerListenerTests.m */, - 33AFDFEE2B8D14C200AAB120 /* RNSentryFramesTrackerListenerTests.h */, 33AFDFF02B8D15E500AAB120 /* RNSentryDependencyContainerTests.m */, - 33AFDFF22B8D15F600AAB120 /* RNSentryDependencyContainerTests.h */, 3360843C2C340C76008CC412 /* RNSentryBreadcrumbTests.swift */, 332D33462CDBDBB600547D76 /* RNSentryReplayOptionsTests.swift */, 3380C6C32CE25ECA0018B9B6 /* RNSentryReplayPostInitTests.swift */, @@ -136,8 +135,11 @@ 3360843A2C32E3A8008CC412 /* RNSentryReplayBreadcrumbConverter.h */, 330F308D2C0F385A002A0D4E /* RNSentryBreadcrumb.h */, 33958C672BFCEF5A00AD1FB6 /* RNSentryOnDrawReporter.h */, + FADF868E2EBD053E00D6652D /* SentrySDKWrapper.h */, 33AFE0132B8F31AF00AAB120 /* RNSentryDependencyContainer.h */, 338739072A7D7D2800950DDD /* RNSentryReplay.h */, + F48F26542EA2A481008A185E /* RNSentryEmitNewFrameEvent.h */, + F48F26552EA2A4D4008A185E /* RNSentryFramesTrackerListener.h */, ); name = RNSentry; sourceTree = ""; @@ -244,6 +246,8 @@ ); outputPaths = ( ); + outputPaths = ( + ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-RNSentryCocoaTesterTests/Pods-RNSentryCocoaTesterTests-resources.sh\"\n"; diff --git a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryDependencyContainerTests.h b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryDependencyContainerTests.h deleted file mode 100644 index c987776703..0000000000 --- a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryDependencyContainerTests.h +++ /dev/null @@ -1,8 +0,0 @@ -#import "SentryFramesTracker.h" -#import -#import - -@interface SentryDependencyContainer : NSObject -+ (instancetype)sharedInstance; -@property (nonatomic, strong) SentryFramesTracker *framesTracker; -@end diff --git a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryDependencyContainerTests.m b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryDependencyContainerTests.m index 1cef19682c..eb53a6322e 100644 --- a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryDependencyContainerTests.m +++ b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryDependencyContainerTests.m @@ -1,8 +1,8 @@ -#import "RNSentryDependencyContainerTests.h" #import "RNSentryDependencyContainer.h" #import #import #import +@import Sentry; @interface RNSentryDependencyContainerTests : XCTestCase diff --git a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryFramesTrackerListenerTests.h b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryFramesTrackerListenerTests.h deleted file mode 100644 index c987776703..0000000000 --- a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryFramesTrackerListenerTests.h +++ /dev/null @@ -1,8 +0,0 @@ -#import "SentryFramesTracker.h" -#import -#import - -@interface SentryDependencyContainer : NSObject -+ (instancetype)sharedInstance; -@property (nonatomic, strong) SentryFramesTracker *framesTracker; -@end diff --git a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryFramesTrackerListenerTests.m b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryFramesTrackerListenerTests.m index 7a877795d6..933d913cb5 100644 --- a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryFramesTrackerListenerTests.m +++ b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryFramesTrackerListenerTests.m @@ -1,8 +1,9 @@ -#import "RNSentryFramesTrackerListenerTests.h" #import "RNSentryDependencyContainer.h" +#import "RNSentryFramesTrackerListener.h" #import #import #import +@import Sentry; @interface RNSentryFramesTrackerListenerTests : XCTestCase diff --git a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryOnDrawReporter+Test.h b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryOnDrawReporter+Test.h index 8a9df3a94e..753983baae 100644 --- a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryOnDrawReporter+Test.h +++ b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryOnDrawReporter+Test.h @@ -1,3 +1,4 @@ +#import "RNSentryEmitNewFrameEvent.h" #import "RNSentryOnDrawReporter.h" #import diff --git a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryReplayOptionsTests.swift b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryReplayOptionsTests.swift index 5dcd2be3ec..340833a1e3 100644 --- a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryReplayOptionsTests.swift +++ b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryReplayOptionsTests.swift @@ -178,7 +178,7 @@ final class RNSentryReplayOptions: XCTestCase { let actualOptions = try! SentryOptionsInternal.initWithDict(optionsDict as! [String: Any]) - XCTAssertTrue(actualOptions.sessionReplay.enableExperimentalViewRenderer) + XCTAssertTrue(actualOptions.sessionReplay.enableViewRendererV2) } func testEnableExperimentalViewRendererTrue() { diff --git a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryTests.m b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryTests.m index 66556e6e27..949492a35a 100644 --- a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryTests.m +++ b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryTests.m @@ -1,7 +1,8 @@ #import "RNSentryTests.h" +#import "RNSentryReplay.h" +#import "SentrySDKWrapper.h" #import #import -#import #import #import @import Sentry; @@ -26,8 +27,10 @@ - (void)testCreateOptionsWithDictionaryRemovesPerformanceProperties , @"enableTracing" : @YES, } ; -SentryOptions *actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary - error:&error]; +mockedReactNativeDictionary = [rnSentry prepareOptions:mockedReactNativeDictionary]; +SentryOptions *actualOptions = + [SentrySDKWrapper createOptionsWithDictionary:mockedReactNativeDictionary + error:&error]; XCTAssertNotNil(actualOptions, @"Did not create sentry options"); XCTAssertNil(error, @"Should not pass no error"); @@ -40,14 +43,14 @@ - (void)testCreateOptionsWithDictionaryRemovesPerformanceProperties - (void)testCaptureFailedRequestsIsDisabled { - RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; NSDictionary *_Nonnull mockedReactNativeDictionary = @{ @"dsn" : @"https://abcd@efgh.ingest.sentry.io/123456", }; - SentryOptions *actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary - error:&error]; + SentryOptions *actualOptions = + [SentrySDKWrapper createOptionsWithDictionary:mockedReactNativeDictionary + error:&error]; XCTAssertNotNil(actualOptions, @"Did not create sentry options"); XCTAssertNil(error, @"Should not pass no error"); @@ -56,30 +59,29 @@ - (void)testCaptureFailedRequestsIsDisabled - (void)testCreateOptionsWithDictionaryNativeCrashHandlingDefault { - RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; NSDictionary *_Nonnull mockedReactNativeDictionary = @{ @"dsn" : @"https://abcd@efgh.ingest.sentry.io/123456", }; - SentryOptions *actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary - error:&error]; + SentryOptions *actualOptions = + [SentrySDKWrapper createOptionsWithDictionary:mockedReactNativeDictionary + error:&error]; XCTAssertNotNil(actualOptions, @"Did not create sentry options"); XCTAssertNil(error, @"Should not pass no error"); - XCTAssertEqual([actualOptions.integrations containsObject:@"SentryCrashIntegration"], true, - @"Did not set native crash handling"); + XCTAssertTrue(actualOptions.enableCrashHandler, @"Did not set native crash handling"); } - (void)testCreateOptionsWithDictionaryAutoPerformanceTracingDefault { - RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; NSDictionary *_Nonnull mockedReactNativeDictionary = @{ @"dsn" : @"https://abcd@efgh.ingest.sentry.io/123456", }; - SentryOptions *actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary - error:&error]; + SentryOptions *actualOptions = + [SentrySDKWrapper createOptionsWithDictionary:mockedReactNativeDictionary + error:&error]; XCTAssertNotNil(actualOptions, @"Did not create sentry options"); XCTAssertNil(error, @"Should not pass no error"); XCTAssertEqual( @@ -88,32 +90,31 @@ - (void)testCreateOptionsWithDictionaryAutoPerformanceTracingDefault - (void)testCreateOptionsWithDictionaryNativeCrashHandlingEnabled { - RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; NSDictionary *_Nonnull mockedReactNativeDictionary = @{ @"dsn" : @"https://abcd@efgh.ingest.sentry.io/123456", @"enableNativeCrashHandling" : @YES, }; - SentryOptions *actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary - error:&error]; + SentryOptions *actualOptions = + [SentrySDKWrapper createOptionsWithDictionary:mockedReactNativeDictionary + error:&error]; XCTAssertNotNil(actualOptions, @"Did not create sentry options"); XCTAssertNil(error, @"Should not pass no error"); - XCTAssertEqual([actualOptions.integrations containsObject:@"SentryCrashIntegration"], true, - @"Did not set native crash handling"); + XCTAssertTrue(actualOptions.enableCrashHandler, @"Did not set native crash handling"); } - (void)testCreateOptionsWithDictionaryAutoPerformanceTracingEnabled { - RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; NSDictionary *_Nonnull mockedReactNativeDictionary = @{ @"dsn" : @"https://abcd@efgh.ingest.sentry.io/123456", @"enableAutoPerformanceTracing" : @YES, }; - SentryOptions *actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary - error:&error]; + SentryOptions *actualOptions = + [SentrySDKWrapper createOptionsWithDictionary:mockedReactNativeDictionary + error:&error]; XCTAssertNotNil(actualOptions, @"Did not create sentry options"); XCTAssertNil(error, @"Should not pass no error"); XCTAssertEqual( @@ -122,32 +123,31 @@ - (void)testCreateOptionsWithDictionaryAutoPerformanceTracingEnabled - (void)testCreateOptionsWithDictionaryNativeCrashHandlingDisabled { - RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; NSDictionary *_Nonnull mockedReactNativeDictionary = @{ @"dsn" : @"https://abcd@efgh.ingest.sentry.io/123456", @"enableNativeCrashHandling" : @NO, }; - SentryOptions *actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary - error:&error]; + SentryOptions *actualOptions = + [SentrySDKWrapper createOptionsWithDictionary:mockedReactNativeDictionary + error:&error]; XCTAssertNotNil(actualOptions, @"Did not create sentry options"); XCTAssertNil(error, @"Should not pass no error"); - XCTAssertEqual([actualOptions.integrations containsObject:@"SentryCrashIntegration"], false, - @"Did not disable native crash handling"); + XCTAssertFalse(actualOptions.enableCrashHandler, @"Did not disable native crash handling"); } - (void)testCreateOptionsWithDictionaryAutoPerformanceTracingDisabled { - RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; NSDictionary *_Nonnull mockedReactNativeDictionary = @{ @"dsn" : @"https://abcd@efgh.ingest.sentry.io/123456", @"enableAutoPerformanceTracing" : @NO, }; - SentryOptions *actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary - error:&error]; + SentryOptions *actualOptions = + [SentrySDKWrapper createOptionsWithDictionary:mockedReactNativeDictionary + error:&error]; XCTAssertNotNil(actualOptions, @"Did not create sentry options"); XCTAssertNil(error, @"Should not pass no error"); XCTAssertEqual(actualOptions.enableAutoPerformanceTracing, false, @@ -156,7 +156,6 @@ - (void)testCreateOptionsWithDictionaryAutoPerformanceTracingDisabled - (void)testCreateOptionsWithDictionarySpotlightEnabled { - RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; NSDictionary *_Nonnull mockedReactNativeDictionary = @{ @@ -164,8 +163,9 @@ - (void)testCreateOptionsWithDictionarySpotlightEnabled @"spotlight" : @YES, @"defaultSidecarUrl" : @"http://localhost:8969/teststream", }; - SentryOptions *actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary - error:&error]; + SentryOptions *actualOptions = + [SentrySDKWrapper createOptionsWithDictionary:mockedReactNativeDictionary + error:&error]; XCTAssertNotNil(actualOptions, @"Did not create sentry options"); XCTAssertNil(error, @"Should not pass no error"); XCTAssertTrue(actualOptions.enableSpotlight, @"Did not enable spotlight"); @@ -174,7 +174,6 @@ - (void)testCreateOptionsWithDictionarySpotlightEnabled - (void)testCreateOptionsWithDictionarySpotlightOne { - RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; NSDictionary *_Nonnull mockedReactNativeDictionary = @{ @@ -182,8 +181,9 @@ - (void)testCreateOptionsWithDictionarySpotlightOne @"spotlight" : @1, @"defaultSidecarUrl" : @"http://localhost:8969/teststream", }; - SentryOptions *actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary - error:&error]; + SentryOptions *actualOptions = + [SentrySDKWrapper createOptionsWithDictionary:mockedReactNativeDictionary + error:&error]; XCTAssertNotNil(actualOptions, @"Did not create sentry options"); XCTAssertNil(error, @"Should not pass no error"); XCTAssertTrue(actualOptions.enableSpotlight, @"Did not enable spotlight"); @@ -192,15 +192,15 @@ - (void)testCreateOptionsWithDictionarySpotlightOne - (void)testCreateOptionsWithDictionarySpotlightUrl { - RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; NSDictionary *_Nonnull mockedReactNativeDictionary = @{ @"dsn" : @"https://abcd@efgh.ingest.sentry.io/123456", @"spotlight" : @"http://localhost:8969/teststream", }; - SentryOptions *actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary - error:&error]; + SentryOptions *actualOptions = + [SentrySDKWrapper createOptionsWithDictionary:mockedReactNativeDictionary + error:&error]; XCTAssertNotNil(actualOptions, @"Did not create sentry options"); XCTAssertNil(error, @"Should not pass no error"); XCTAssertTrue(actualOptions.enableSpotlight, @"Did not enable spotlight"); @@ -209,15 +209,15 @@ - (void)testCreateOptionsWithDictionarySpotlightUrl - (void)testCreateOptionsWithDictionarySpotlightDisabled { - RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; NSDictionary *_Nonnull mockedReactNativeDictionary = @{ @"dsn" : @"https://abcd@efgh.ingest.sentry.io/123456", @"spotlight" : @NO, }; - SentryOptions *actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary - error:&error]; + SentryOptions *actualOptions = + [SentrySDKWrapper createOptionsWithDictionary:mockedReactNativeDictionary + error:&error]; XCTAssertNotNil(actualOptions, @"Did not create sentry options"); XCTAssertNil(error, @"Should not pass no error"); XCTAssertFalse(actualOptions.enableSpotlight, @"Did not disable spotlight"); @@ -225,15 +225,15 @@ - (void)testCreateOptionsWithDictionarySpotlightDisabled - (void)testCreateOptionsWithDictionarySpotlightZero { - RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; NSDictionary *_Nonnull mockedReactNativeDictionary = @{ @"dsn" : @"https://abcd@efgh.ingest.sentry.io/123456", @"spotlight" : @0, }; - SentryOptions *actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary - error:&error]; + SentryOptions *actualOptions = + [SentrySDKWrapper createOptionsWithDictionary:mockedReactNativeDictionary + error:&error]; XCTAssertNotNil(actualOptions, @"Did not create sentry options"); XCTAssertNil(error, @"Should not pass no error"); XCTAssertFalse(actualOptions.enableSpotlight, @"Did not disable spotlight"); @@ -241,7 +241,6 @@ - (void)testCreateOptionsWithDictionarySpotlightZero - (void)testCreateOptionsWithDictionaryEnableUnhandledCPPExceptionsV2Enabled { - RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; NSDictionary *_Nonnull mockedReactNativeDictionary = @{ @@ -250,8 +249,9 @@ - (void)testCreateOptionsWithDictionaryEnableUnhandledCPPExceptionsV2Enabled @"enableUnhandledCPPExceptionsV2" : @YES, }, }; - SentryOptions *actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary - error:&error]; + SentryOptions *actualOptions = + [SentrySDKWrapper createOptionsWithDictionary:mockedReactNativeDictionary + error:&error]; XCTAssertNotNil(actualOptions, @"Did not create sentry options"); XCTAssertNil(error, @"Should not pass no error"); @@ -267,7 +267,6 @@ - (void)testCreateOptionsWithDictionaryEnableUnhandledCPPExceptionsV2Enabled - (void)testCreateOptionsWithDictionaryEnableUnhandledCPPExceptionsV2Disabled { - RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; NSDictionary *_Nonnull mockedReactNativeDictionary = @{ @@ -276,8 +275,9 @@ - (void)testCreateOptionsWithDictionaryEnableUnhandledCPPExceptionsV2Disabled @"enableUnhandledCPPExceptionsV2" : @NO, }, }; - SentryOptions *actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary - error:&error]; + SentryOptions *actualOptions = + [SentrySDKWrapper createOptionsWithDictionary:mockedReactNativeDictionary + error:&error]; XCTAssertNotNil(actualOptions, @"Did not create sentry options"); XCTAssertNil(error, @"Should not pass no error"); @@ -293,14 +293,14 @@ - (void)testCreateOptionsWithDictionaryEnableUnhandledCPPExceptionsV2Disabled - (void)testCreateOptionsWithDictionaryEnableUnhandledCPPExceptionsV2Default { - RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; NSDictionary *_Nonnull mockedReactNativeDictionary = @{ @"dsn" : @"https://abcd@efgh.ingest.sentry.io/123456", }; - SentryOptions *actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary - error:&error]; + SentryOptions *actualOptions = + [SentrySDKWrapper createOptionsWithDictionary:mockedReactNativeDictionary + error:&error]; XCTAssertNotNil(actualOptions, @"Did not create sentry options"); XCTAssertNil(error, @"Should not pass no error"); @@ -317,15 +317,15 @@ - (void)testCreateOptionsWithDictionaryEnableUnhandledCPPExceptionsV2Default - (void)testCreateOptionsWithDictionaryEnableLogsEnabled { - RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; NSDictionary *_Nonnull mockedReactNativeDictionary = @{ @"dsn" : @"https://abcd@efgh.ingest.sentry.io/123456", @"enableLogs" : @YES, }; - SentryOptions *actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary - error:&error]; + SentryOptions *actualOptions = + [SentrySDKWrapper createOptionsWithDictionary:mockedReactNativeDictionary + error:&error]; XCTAssertNotNil(actualOptions, @"Did not create sentry options"); XCTAssertNil(error, @"Should not pass no error"); @@ -336,33 +336,33 @@ - (void)testCreateOptionsWithDictionaryEnableLogsEnabled - (void)testCreateOptionsWithDictionaryEnableLogsDisabled { - RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; NSDictionary *_Nonnull mockedReactNativeDictionary = @{ @"dsn" : @"https://abcd@efgh.ingest.sentry.io/123456", @"enableLogs" : @NO, }; - SentryOptions *actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary - error:&error]; + SentryOptions *actualOptions = + [SentrySDKWrapper createOptionsWithDictionary:mockedReactNativeDictionary + error:&error]; XCTAssertNotNil(actualOptions, @"Did not create sentry options"); XCTAssertNil(error, @"Should not pass no error"); - + BOOL enableLogs = [[actualOptions valueForKey:@"enableLogs"] boolValue]; XCTAssertFalse(enableLogs, @"enableLogs should be disabled"); } - (void)testPassesErrorOnWrongDsn { - RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; NSDictionary *_Nonnull mockedReactNativeDictionary = @{ @"dsn" : @"not_a_valid_dsn", }; - SentryOptions *actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary - error:&error]; + SentryOptions *actualOptions = + [SentrySDKWrapper createOptionsWithDictionary:mockedReactNativeDictionary + error:&error]; XCTAssertNil(actualOptions, @"Created invalid sentry options"); XCTAssertNotNil(error, @"Did not created error on invalid dsn"); @@ -377,8 +377,9 @@ - (void)testBeforeBreadcrumbsCallbackFiltersOutSentryDsnRequestBreadcrumbs @"dsn" : @"https://abc@def.ingest.sentry.io/1234567", @"devServerUrl" : @"http://localhost:8081" }; - SentryOptions *options = [rnSentry createOptionsWithDictionary:mockedDictionary error:&error]; - + mockedDictionary = [rnSentry prepareOptions:mockedDictionary]; + SentryOptions *options = [SentrySDKWrapper createOptionsWithDictionary:mockedDictionary + error:&error]; SentryBreadcrumb *breadcrumb = [[SentryBreadcrumb alloc] init]; breadcrumb.type = @"http"; breadcrumb.data = @{ @"url" : @"https://def.ingest.sentry.io/1234567" }; @@ -390,15 +391,14 @@ - (void)testBeforeBreadcrumbsCallbackFiltersOutSentryDsnRequestBreadcrumbs - (void)testBeforeBreadcrumbsCallbackFiltersOutDevServerRequestBreadcrumbs { - RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; NSString *mockDevServer = @"http://localhost:8081"; NSDictionary *_Nonnull mockedDictionary = @{ @"dsn" : @"https://abc@def.ingest.sentry.io/1234567", @"devServerUrl" : mockDevServer }; - SentryOptions *options = [rnSentry createOptionsWithDictionary:mockedDictionary error:&error]; - + SentryOptions *options = [SentrySDKWrapper createOptionsWithDictionary:mockedDictionary + error:&error]; SentryBreadcrumb *breadcrumb = [[SentryBreadcrumb alloc] init]; breadcrumb.type = @"http"; breadcrumb.data = @{ @"url" : mockDevServer }; @@ -410,15 +410,14 @@ - (void)testBeforeBreadcrumbsCallbackFiltersOutDevServerRequestBreadcrumbs - (void)testBeforeBreadcrumbsCallbackDoesNotFiltersOutNonDevServerOrDsnRequestBreadcrumbs { - RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; NSDictionary *_Nonnull mockedDictionary = @{ @"dsn" : @"https://abc@def.ingest.sentry.io/1234567", @"devServerUrl" : @"http://localhost:8081" }; - SentryOptions *options = [rnSentry createOptionsWithDictionary:mockedDictionary error:&error]; - + SentryOptions *options = [SentrySDKWrapper createOptionsWithDictionary:mockedDictionary + error:&error]; SentryBreadcrumb *breadcrumb = [[SentryBreadcrumb alloc] init]; breadcrumb.type = @"http"; breadcrumb.data = @{ @"url" : @"http://testurl.com/service" }; @@ -430,14 +429,13 @@ - (void)testBeforeBreadcrumbsCallbackDoesNotFiltersOutNonDevServerOrDsnRequestBr - (void)testBeforeBreadcrumbsCallbackKeepsBreadcrumbWhenDevServerUrlIsNotPassedAndDsnDoesNotMatch { - RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; NSDictionary *_Nonnull mockedDictionary = @{ // dsn is always validated in SentryOptions initialization @"dsn" : @"https://abc@def.ingest.sentry.io/1234567" }; - SentryOptions *options = [rnSentry createOptionsWithDictionary:mockedDictionary error:&error]; - + SentryOptions *options = [SentrySDKWrapper createOptionsWithDictionary:mockedDictionary + error:&error]; SentryBreadcrumb *breadcrumb = [[SentryBreadcrumb alloc] init]; breadcrumb.type = @"http"; breadcrumb.data = @{ @"url" : @"http://testurl.com/service" }; @@ -618,11 +616,13 @@ - (void)testIgnoreErrorsDropsMatchingExceptionValue { RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; - NSDictionary *mockedOptions = @{ + NSMutableDictionary *mockedOptions = [@{ @"dsn" : @"https://abc@def.ingest.sentry.io/1234567", @"ignoreErrorsRegex" : @[ @"IgnoreMe.*" ] - }; - SentryOptions *options = [rnSentry createOptionsWithDictionary:mockedOptions error:&error]; + } mutableCopy]; + mockedOptions = [rnSentry prepareOptions:mockedOptions]; + SentryOptions *options = [SentrySDKWrapper createOptionsWithDictionary:mockedOptions + error:&error]; XCTAssertNotNil(options); XCTAssertNil(error); SentryEvent *event = [[SentryEvent alloc] init]; @@ -637,11 +637,14 @@ - (void)testIgnoreErrorsDropsMatchingEventMessage { RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; - NSDictionary *mockedOptions = @{ + NSMutableDictionary *mockedOptions = [@{ @"dsn" : @"https://abc@def.ingest.sentry.io/1234567", @"ignoreErrorsStr" : @[ @"DropThisError" ] - }; - SentryOptions *options = [rnSentry createOptionsWithDictionary:mockedOptions error:&error]; + } mutableCopy]; + mockedOptions = [rnSentry prepareOptions:mockedOptions]; + SentryOptions *options = [SentrySDKWrapper createOptionsWithDictionary:mockedOptions + error:&error]; + XCTAssertNotNil(options); XCTAssertNotNil(options); XCTAssertNil(error); SentryEvent *event = [[SentryEvent alloc] init]; @@ -656,11 +659,14 @@ - (void)testIgnoreErrorsDoesNotDropNonMatchingEvent { RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; - NSDictionary *mockedOptions = @{ + NSMutableDictionary *mockedOptions = [@{ @"dsn" : @"https://abc@def.ingest.sentry.io/1234567", @"ignoreErrorsRegex" : @[ @"IgnoreMe.*" ] - }; - SentryOptions *options = [rnSentry createOptionsWithDictionary:mockedOptions error:&error]; + } mutableCopy]; + mockedOptions = [rnSentry prepareOptions:mockedOptions]; + SentryOptions *options = [SentrySDKWrapper createOptionsWithDictionary:mockedOptions + error:&error]; + XCTAssertNotNil(options); XCTAssertNotNil(options); XCTAssertNil(error); SentryEvent *event = [[SentryEvent alloc] init]; @@ -678,11 +684,14 @@ - (void)testIgnoreErrorsDropsMatchingExactString { RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; - NSDictionary *mockedOptions = @{ + NSMutableDictionary *mockedOptions = [@{ @"dsn" : @"https://abc@def.ingest.sentry.io/1234567", @"ignoreErrorsStr" : @[ @"ExactError" ] - }; - SentryOptions *options = [rnSentry createOptionsWithDictionary:mockedOptions error:&error]; + } mutableCopy]; + mockedOptions = [rnSentry prepareOptions:mockedOptions]; + SentryOptions *options = [SentrySDKWrapper createOptionsWithDictionary:mockedOptions + error:&error]; + XCTAssertNotNil(options); XCTAssertNotNil(options); XCTAssertNil(error); SentryEvent *event = [[SentryEvent alloc] init]; @@ -697,13 +706,16 @@ - (void)testIgnoreErrorsRegexAndStringBothWork { RNSentry *rnSentry = [[RNSentry alloc] init]; NSError *error = nil; - NSDictionary *mockedOptions = @{ + NSMutableDictionary *mockedOptions = [@{ @"dsn" : @"https://abc@def.ingest.sentry.io/1234567", @"ignoreErrorsStr" : @[ @"ExactError" ], @"ignoreErrorsRegex" : @[ @"IgnoreMe.*" ], - }; - SentryOptions *options = [rnSentry createOptionsWithDictionary:mockedOptions error:&error]; + } mutableCopy]; + mockedOptions = [rnSentry prepareOptions:mockedOptions]; + SentryOptions *options = [SentrySDKWrapper createOptionsWithDictionary:mockedOptions + error:&error]; + XCTAssertNotNil(options); XCTAssertNotNil(options); XCTAssertNil(error); // Test regex match @@ -729,4 +741,8 @@ - (void)testIgnoreErrorsRegexAndStringBothWork XCTAssertNotNil(result3, @"Event with non-matching error should not be dropped"); } + + + + @end diff --git a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryUserTests.m b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryUserTests.m index 0111e8ddcf..987dc6d2e1 100644 --- a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryUserTests.m +++ b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryUserTests.m @@ -14,7 +14,6 @@ - (void)testValidUser [expected setIpAddress:@"192.168.1.1"]; [expected setEmail:@"test@example.com"]; [expected setUsername:@"testuser"]; - [expected setSegment:@"testsegment"]; [expected setData:@{ @"foo" : @"bar", @"baz" : @123, @@ -26,7 +25,6 @@ - (void)testValidUser @"ip_address" : @"192.168.1.1", @"email" : @"test@example.com", @"username" : @"testuser", - @"segment" : @"testsegment", } otherUserKeys:@{ @"foo" : @"bar", @@ -67,7 +65,6 @@ - (void)testInvalidUser @"ip_address" : @ {}, @"email" : @ {}, @"username" : @ {}, - @"segment" : @[], } otherUserKeys:nil]; @@ -84,7 +81,6 @@ - (void)testPartiallyInvalidUser @"ip_address" : @ {}, @"email" : @ {}, @"username" : @ {}, - @"segment" : @[], } otherUserKeys:nil]; @@ -100,7 +96,6 @@ - (void)testNullValuesUser @"ip_address" : [NSNull null], @"email" : [NSNull null], @"username" : [NSNull null], - @"segment" : [NSNull null], } otherUserKeys:nil]; diff --git a/packages/core/ios/RNSentry+fetchNativeStack.m b/packages/core/ios/RNSentry+fetchNativeStack.m index ffb404fa22..d10f82108c 100644 --- a/packages/core/ios/RNSentry+fetchNativeStack.m +++ b/packages/core/ios/RNSentry+fetchNativeStack.m @@ -2,16 +2,6 @@ #import "RNSentryBreadcrumb.h" #import "RNSentryId.h" #import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import @import Sentry; // This method was moved to a new category so we can use `@import Sentry` to use Sentry's Swift diff --git a/packages/core/ios/RNSentry.h b/packages/core/ios/RNSentry.h index 78f48f5f4b..5b163baca9 100644 --- a/packages/core/ios/RNSentry.h +++ b/packages/core/ios/RNSentry.h @@ -8,7 +8,6 @@ #import #import -#import typedef int (*SymbolicateCallbackType)(const void *, Dl_info *); @@ -21,8 +20,7 @@ typedef int (*SymbolicateCallbackType)(const void *, Dl_info *); @interface RNSentry : RCTEventEmitter -- (SentryOptions *_Nullable)createOptionsWithDictionary:(NSDictionary *_Nonnull)options - error:(NSError *_Nullable *_Nonnull)errorPointer; +- (NSMutableDictionary *)prepareOptions:(NSDictionary *)options; - (void)setEventOriginTag:(SentryEvent *)event; diff --git a/packages/core/ios/RNSentry.mm b/packages/core/ios/RNSentry.mm index 0305af0a08..ecba51576a 100644 --- a/packages/core/ios/RNSentry.mm +++ b/packages/core/ios/RNSentry.mm @@ -21,14 +21,10 @@ #import #import #import -#import #import -#import #import #import #import -#import -#import #import // This guard prevents importing Hermes in JSC apps @@ -49,7 +45,7 @@ #endif #if SENTRY_HAS_UIKIT -# import "RNSentryFramesTrackerListener.h" +# import "RNSentryEmitNewFrameEvent.h" # import "RNSentryRNSScreen.h" #endif @@ -86,24 +82,64 @@ - (instancetype)init return self; } +- (NSMutableDictionary *)prepareOptions:(NSDictionary *)options +{ + SentryBeforeSendEventCallback beforeSend = ^SentryEvent *(SentryEvent *event) { + // We don't want to send an event after startup that came from a Unhandled JS Exception of + // React Native because we sent it already before the app crashed. + if (nil != event.exceptions.firstObject.type && + [event.exceptions.firstObject.type rangeOfString:@"Unhandled JS Exception"].location + != NSNotFound) { + return nil; + } + + // Regex and Str are set when one of them has value so we only need to check one of them. + if (self->_ignoreErrorPatternsStr || self->_ignoreErrorPatternsRegex) { + for (SentryException *exception in event.exceptions) { + if ([self shouldIgnoreError:exception.value]) { + return nil; + } + } + if ([self shouldIgnoreError:event.message.message]) { + return nil; + } + } + + [self setEventOriginTag:event]; + return event; + }; + + NSMutableDictionary *mutableOptions = [options mutableCopy]; + [mutableOptions setValue:beforeSend forKey:@"beforeSend"]; + + // remove performance traces sample rate and traces sampler since we don't want to synchronize + // these configurations to the Native SDKs. The user could tho initialize the SDK manually and + // set themselves. + [mutableOptions removeObjectForKey:@"tracesSampleRate"]; + [mutableOptions removeObjectForKey:@"tracesSampler"]; + [mutableOptions removeObjectForKey:@"enableTracing"]; + + [self trySetIgnoreErrors:mutableOptions]; + + return mutableOptions; +} + RCT_EXPORT_MODULE() RCT_EXPORT_METHOD(initNativeSdk : (NSDictionary *_Nonnull)options resolve : ( RCTPromiseResolveBlock)resolve rejecter : (RCTPromiseRejectBlock)reject) { + NSMutableDictionary *mutableOptions = [self prepareOptions:options]; +#if SENTRY_TARGET_REPLAY_SUPPORTED + [RNSentryReplay updateOptions:mutableOptions]; +#endif NSError *error = nil; - SentryOptions *sentryOptions = [self createOptionsWithDictionary:options error:&error]; + [SentrySDKWrapper setupWithDictionary:mutableOptions + error:&error]; if (error != nil) { reject(@"SentryReactNative", error.localizedDescription, error); return; } - NSString *sdkVersion = [PrivateSentrySDKOnly getSdkVersionString]; - [PrivateSentrySDKOnly setSdkName:NATIVE_SDK_NAME andVersionString:sdkVersion]; - [PrivateSentrySDKOnly addSdkPackage:REACT_NATIVE_SDK_PACKAGE_NAME - version:REACT_NATIVE_SDK_PACKAGE_VERSION]; - - [SentrySDKWrapper startWithOptions:sentryOptions]; - #if TARGET_OS_IPHONE || TARGET_OS_MACCATALYST BOOL appIsActive = [[UIApplication sharedApplication] applicationState] == UIApplicationStateActive; @@ -114,8 +150,8 @@ - (instancetype)init // If the app is active/in foreground, and we have not sent the SentryHybridSdkDidBecomeActive // notification, send it. if (appIsActive && !sentHybridSdkDidBecomeActive - && (PrivateSentrySDKOnly.options.enableAutoSessionTracking - || PrivateSentrySDKOnly.options.enableWatchdogTerminationTracking)) { + && ([SentrySDKWrapper enableAutoSessionTracking] || + [SentrySDKWrapper enableWatchdogTerminationTracking])) { [[NSNotificationCenter defaultCenter] postNotificationName:@"SentryHybridSdkDidBecomeActive" object:nil]; @@ -129,7 +165,7 @@ - (instancetype)init resolve(@YES); } -- (void)trySetIgnoreErrors:(NSMutableDictionary *)options +- (void)trySetIgnoreErrors:(NSDictionary *)options { NSArray *ignoreErrorsStr = nil; NSArray *ignoreErrorsRegex = nil; @@ -195,138 +231,6 @@ - (BOOL)shouldIgnoreError:(NSString *)message return NO; } -- (SentryOptions *_Nullable)createOptionsWithDictionary:(NSDictionary *_Nonnull)options - error:(NSError *_Nonnull *_Nonnull)errorPointer -{ - SentryBeforeSendEventCallback beforeSend = ^SentryEvent *(SentryEvent *event) { - // We don't want to send an event after startup that came from a Unhandled JS Exception of - // React Native because we sent it already before the app crashed. - if (nil != event.exceptions.firstObject.type && - [event.exceptions.firstObject.type rangeOfString:@"Unhandled JS Exception"].location - != NSNotFound) { - return nil; - } - - // Regex and Str are set when one of them has value so we only need to check one of them. - if (self->_ignoreErrorPatternsStr || self->_ignoreErrorPatternsRegex) { - for (SentryException *exception in event.exceptions) { - if ([self shouldIgnoreError:exception.value]) { - return nil; - } - } - if ([self shouldIgnoreError:event.message.message]) { - return nil; - } - } - - [self setEventOriginTag:event]; - return event; - }; - - NSMutableDictionary *mutableOptions = [options mutableCopy]; - [mutableOptions setValue:beforeSend forKey:@"beforeSend"]; - - // remove performance traces sample rate and traces sampler since we don't want to synchronize - // these configurations to the Native SDKs. The user could tho initialize the SDK manually and - // set themselves. - [mutableOptions removeObjectForKey:@"tracesSampleRate"]; - [mutableOptions removeObjectForKey:@"tracesSampler"]; - [mutableOptions removeObjectForKey:@"enableTracing"]; - -#if SENTRY_TARGET_REPLAY_SUPPORTED - [RNSentryReplay updateOptions:mutableOptions]; -#endif - - SentryOptions *sentryOptions = [SentryOptionsInternal initWithDict:mutableOptions - didFailWithError:errorPointer]; - if (*errorPointer != nil) { - return nil; - } - - // Exclude Dev Server and Sentry Dsn request from Breadcrumbs - NSString *dsn = [self getURLFromDSN:[mutableOptions valueForKey:@"dsn"]]; - NSString *devServerUrl = [mutableOptions valueForKey:@"devServerUrl"]; - sentryOptions.beforeBreadcrumb - = ^SentryBreadcrumb *_Nullable(SentryBreadcrumb *_Nonnull breadcrumb) - { - NSString *url = breadcrumb.data[@"url"] ?: @""; - - if ([@"http" isEqualToString:breadcrumb.type] - && ((dsn != nil && [url hasPrefix:dsn]) - || (devServerUrl != nil && [url hasPrefix:devServerUrl]))) { - return nil; - } - return breadcrumb; - }; - - if ([mutableOptions valueForKey:@"enableNativeCrashHandling"] != nil) { - BOOL enableNativeCrashHandling = [mutableOptions[@"enableNativeCrashHandling"] boolValue]; - - if (!enableNativeCrashHandling) { - NSMutableArray *integrations = sentryOptions.integrations.mutableCopy; - [integrations removeObject:@"SentryCrashIntegration"]; - sentryOptions.integrations = integrations; - } - } - - // Set spotlight option - if ([mutableOptions valueForKey:@"spotlight"] != nil) { - id spotlightValue = [mutableOptions valueForKey:@"spotlight"]; - if ([spotlightValue isKindOfClass:[NSString class]]) { - NSLog(@"Using Spotlight on address: %@", spotlightValue); - sentryOptions.enableSpotlight = true; - sentryOptions.spotlightUrl = spotlightValue; - } else if ([spotlightValue isKindOfClass:[NSNumber class]]) { - sentryOptions.enableSpotlight = [spotlightValue boolValue]; - id defaultSpotlightUrl = [mutableOptions valueForKey:@"defaultSidecarUrl"]; - if (defaultSpotlightUrl != nil) { - sentryOptions.spotlightUrl = defaultSpotlightUrl; - } - } - } - - if ([mutableOptions valueForKey:@"enableLogs"] != nil) { - id enableLogsValue = [mutableOptions valueForKey:@"enableLogs"]; - if ([enableLogsValue isKindOfClass:[NSNumber class]]) { - [RNSentryExperimentalOptions setEnableLogs:[enableLogsValue boolValue] - sentryOptions:sentryOptions]; - } - } - [self trySetIgnoreErrors:mutableOptions]; - - // Enable the App start and Frames tracking measurements - if ([mutableOptions valueForKey:@"enableAutoPerformanceTracing"] != nil) { - BOOL enableAutoPerformanceTracing = - [mutableOptions[@"enableAutoPerformanceTracing"] boolValue]; - PrivateSentrySDKOnly.appStartMeasurementHybridSDKMode = enableAutoPerformanceTracing; -#if TARGET_OS_IPHONE || TARGET_OS_MACCATALYST - PrivateSentrySDKOnly.framesTrackingMeasurementHybridSDKMode = enableAutoPerformanceTracing; -#endif - } - - // Failed requests can only be enabled in one SDK to avoid duplicates - sentryOptions.enableCaptureFailedRequests = NO; - - NSDictionary *experiments = options[@"_experiments"]; - if (experiments != nil && [experiments isKindOfClass:[NSDictionary class]]) { - BOOL enableUnhandledCPPExceptions = - [experiments[@"enableUnhandledCPPExceptionsV2"] boolValue]; - [RNSentryExperimentalOptions setEnableUnhandledCPPExceptionsV2:enableUnhandledCPPExceptions - sentryOptions:sentryOptions]; - } - - return sentryOptions; -} - -- (NSString *_Nullable)getURLFromDSN:(NSString *)dsn -{ - NSURL *url = [NSURL URLWithString:dsn]; - if (!url) { - return nil; - } - return [NSString stringWithFormat:@"%@://%@", url.scheme, url.host]; -} - - (void)setEventOriginTag:(SentryEvent *)event { if (event.sdk != nil) { @@ -455,7 +359,7 @@ - (void)stopObserving contexts[@"os"] = os; } - NSString *releaseName = SentrySDKInternal.options.releaseName; + NSString *releaseName = [SentrySDKWrapper releaseName]; if (releaseName) { contexts[@"release"] = releaseName; } @@ -487,7 +391,7 @@ - (void)stopObserving RCT_EXPORT_METHOD(fetchNativeDeviceContexts : (RCTPromiseResolveBlock)resolve rejecter : ( RCTPromiseRejectBlock)reject) { - if (PrivateSentrySDKOnly.options.debug) { + if ([SentrySDKWrapper debug]) { NSLog(@"Bridge call to: deviceContexts"); } __block NSMutableDictionary *serializedScope; @@ -502,7 +406,7 @@ - (void)stopObserving forKey:@"user"]; } - if (PrivateSentrySDKOnly.options.debug) { + if ([SentrySDKWrapper debug]) { NSData *data = [NSJSONSerialization dataWithJSONObject:serializedScope options:0 error:nil]; @@ -711,10 +615,6 @@ + (SentryUser *_Nullable)userFrom:(NSDictionary *)userKeys if ([username isKindOfClass:NSString.class]) { [userInstance setUsername:username]; } - id segment = [userKeys valueForKey:@"segment"]; - if ([segment isKindOfClass:NSString.class]) { - [userInstance setSegment:segment]; - } if ([userDataKeys isKindOfClass:NSDictionary.class]) { [userInstance setData:userDataKeys]; diff --git a/packages/core/ios/RNSentryDependencyContainer.h b/packages/core/ios/RNSentryDependencyContainer.h index cd3eca59c7..b3b3ff5233 100644 --- a/packages/core/ios/RNSentryDependencyContainer.h +++ b/packages/core/ios/RNSentryDependencyContainer.h @@ -1,6 +1,7 @@ #import -#import "RNSentryFramesTrackerListener.h" +#import "RNSentryEmitNewFrameEvent.h" +@class RNSentryFramesTrackerListener; @interface RNSentryDependencyContainer : NSObject SENTRY_NO_INIT diff --git a/packages/core/ios/RNSentryDependencyContainer.m b/packages/core/ios/RNSentryDependencyContainer.m index e91cac7f81..0147e0b395 100644 --- a/packages/core/ios/RNSentryDependencyContainer.m +++ b/packages/core/ios/RNSentryDependencyContainer.m @@ -1,5 +1,5 @@ #import "RNSentryDependencyContainer.h" -#import +#import "RNSentryFramesTrackerListener.h" @implementation RNSentryDependencyContainer { NSObject *sentryDependencyContainerLock; diff --git a/packages/core/ios/RNSentryEmitNewFrameEvent.h b/packages/core/ios/RNSentryEmitNewFrameEvent.h new file mode 100644 index 0000000000..473c91cc77 --- /dev/null +++ b/packages/core/ios/RNSentryEmitNewFrameEvent.h @@ -0,0 +1,3 @@ +#import + +typedef void (^RNSentryEmitNewFrameEvent)(NSNumber *newFrameTimestampInSeconds); diff --git a/packages/core/ios/RNSentryFramesTrackerListener.h b/packages/core/ios/RNSentryFramesTrackerListener.h index 627b3059f4..630f0daeee 100644 --- a/packages/core/ios/RNSentryFramesTrackerListener.h +++ b/packages/core/ios/RNSentryFramesTrackerListener.h @@ -2,11 +2,11 @@ #if SENTRY_HAS_UIKIT +# import "RNSentryEmitNewFrameEvent.h" # import # import -# import -typedef void (^RNSentryEmitNewFrameEvent)(NSNumber *newFrameTimestampInSeconds); +@import Sentry; @protocol RNSentryFramesTrackerListenerProtocol diff --git a/packages/core/ios/RNSentryFramesTrackerListener.m b/packages/core/ios/RNSentryFramesTrackerListener.m index 4a3c7d99cd..2e090bc711 100644 --- a/packages/core/ios/RNSentryFramesTrackerListener.m +++ b/packages/core/ios/RNSentryFramesTrackerListener.m @@ -2,6 +2,8 @@ #if SENTRY_HAS_UIKIT +@import Sentry; + @implementation RNSentryFramesTrackerListener - (instancetype)initWithSentryFramesTracker:(SentryFramesTracker *)framesTracker diff --git a/packages/core/ios/RNSentryOnDrawReporter.h b/packages/core/ios/RNSentryOnDrawReporter.h index 5c4083015d..b462dc4f0b 100644 --- a/packages/core/ios/RNSentryOnDrawReporter.h +++ b/packages/core/ios/RNSentryOnDrawReporter.h @@ -2,10 +2,11 @@ #if SENTRY_HAS_UIKIT -# import "RNSentryFramesTrackerListener.h" # import # import +@protocol RNSentryFramesTrackerListenerProtocol; + @interface RNSentryOnDrawReporter : RCTViewManager @end diff --git a/packages/core/ios/RNSentryOnDrawReporter.m b/packages/core/ios/RNSentryOnDrawReporter.m index dc11bc9c51..44d8024a6f 100644 --- a/packages/core/ios/RNSentryOnDrawReporter.m +++ b/packages/core/ios/RNSentryOnDrawReporter.m @@ -1,10 +1,10 @@ #import "RNSentryOnDrawReporter.h" +#import "RNSentryEmitNewFrameEvent.h" +#import "RNSentryFramesTrackerListener.h" #import "RNSentryTimeToDisplay.h" #if SENTRY_HAS_UIKIT -# import - @implementation RNSentryOnDrawReporter RCT_EXPORT_MODULE(RNSentryOnDrawReporter) diff --git a/packages/core/ios/RNSentryRNSScreen.m b/packages/core/ios/RNSentryRNSScreen.m index 20c42ab4c4..90b2e733d3 100644 --- a/packages/core/ios/RNSentryRNSScreen.m +++ b/packages/core/ios/RNSentryRNSScreen.m @@ -2,11 +2,10 @@ #if SENTRY_HAS_UIKIT -# import -# import -# import - # import "RNSentryDependencyContainer.h" +# import "RNSentryFramesTrackerListener.h" +# import +@import Sentry; @implementation RNSentryRNSScreen diff --git a/packages/core/ios/SentrySDKWrapper.h b/packages/core/ios/SentrySDKWrapper.h index 9040d032ab..483b0bcdac 100644 --- a/packages/core/ios/SentrySDKWrapper.h +++ b/packages/core/ios/SentrySDKWrapper.h @@ -15,4 +15,18 @@ + (void)startWithOptions:(SentryOptions *)options; ++ (SentryOptions *)createOptionsWithDictionary:(NSDictionary *)options + error:(NSError **)errorPointer; + ++ (void)setupWithDictionary:(NSDictionary *)options + error:(NSError **)errorPointer; + ++ (BOOL)debug; + ++ (NSString *)releaseName; + ++ (BOOL)enableAutoSessionTracking; + ++ (BOOL)enableWatchdogTerminationTracking; + @end diff --git a/packages/core/ios/SentrySDKWrapper.m b/packages/core/ios/SentrySDKWrapper.m index 0845f1ff3e..dc26761b1e 100644 --- a/packages/core/ios/SentrySDKWrapper.m +++ b/packages/core/ios/SentrySDKWrapper.m @@ -1,4 +1,6 @@ #import "SentrySDKWrapper.h" +#import "RNSentryExperimentalOptions.h" +#import "RNSentryVersion.h" @import Sentry; @implementation SentrySDKWrapper @@ -28,4 +30,130 @@ + (void)configureScope:(void (^)(SentryScope *scope))callback [SentrySDK configureScope:callback]; } ++ (SentryOptions *)createOptionsWithDictionary:(NSDictionary *)options + error:(NSError *__autoreleasing *)errorPointer +{ + NSString *dsn = [self getURLFromDSN:[options valueForKey:@"dsn"]]; + SentryOptions *sentryOptions = [SentryOptionsInternal initWithDict:options + didFailWithError:errorPointer]; + if (*errorPointer != nil) { + return nil; + } + + // Exclude Dev Server and Sentry Dsn request from Breadcrumbs + NSString *devServerUrl = [options valueForKey:@"devServerUrl"]; + sentryOptions.beforeBreadcrumb + = ^SentryBreadcrumb *_Nullable(SentryBreadcrumb *_Nonnull breadcrumb) + { + NSString *url = breadcrumb.data[@"url"] ?: @""; + + if ([@"http" isEqualToString:breadcrumb.type] + && ((dsn != nil && [url hasPrefix:dsn]) + || (devServerUrl != nil && [url hasPrefix:devServerUrl]))) { + return nil; + } + return breadcrumb; + }; + + if ([options valueForKey:@"enableNativeCrashHandling"] != nil) { + BOOL enableNativeCrashHandling = [options[@"enableNativeCrashHandling"] boolValue]; + + if (!enableNativeCrashHandling) { + sentryOptions.enableCrashHandler = NO; + } + } + + // Set spotlight option + if ([options valueForKey:@"spotlight"] != nil) { + id spotlightValue = [options valueForKey:@"spotlight"]; + if ([spotlightValue isKindOfClass:[NSString class]]) { + NSLog(@"Using Spotlight on address: %@", spotlightValue); + sentryOptions.enableSpotlight = true; + sentryOptions.spotlightUrl = spotlightValue; + } else if ([spotlightValue isKindOfClass:[NSNumber class]]) { + sentryOptions.enableSpotlight = [spotlightValue boolValue]; + id defaultSpotlightUrl = [options valueForKey:@"defaultSidecarUrl"]; + if (defaultSpotlightUrl != nil) { + sentryOptions.spotlightUrl = defaultSpotlightUrl; + } + } + } + + if ([options valueForKey:@"enableLogs"] != nil) { + id enableLogsValue = [options valueForKey:@"enableLogs"]; + if ([enableLogsValue isKindOfClass:[NSNumber class]]) { + [RNSentryExperimentalOptions setEnableLogs:[enableLogsValue boolValue] + sentryOptions:sentryOptions]; + } + } + + // Enable the App start and Frames tracking measurements + if ([options valueForKey:@"enableAutoPerformanceTracing"] != nil) { + BOOL enableAutoPerformanceTracing = [options[@"enableAutoPerformanceTracing"] boolValue]; + PrivateSentrySDKOnly.appStartMeasurementHybridSDKMode = enableAutoPerformanceTracing; +#if TARGET_OS_IPHONE || TARGET_OS_MACCATALYST + PrivateSentrySDKOnly.framesTrackingMeasurementHybridSDKMode = enableAutoPerformanceTracing; +#endif + } + + // Failed requests can only be enabled in one SDK to avoid duplicates + sentryOptions.enableCaptureFailedRequests = NO; + + NSDictionary *experiments = options[@"_experiments"]; + if (experiments != nil && [experiments isKindOfClass:[NSDictionary class]]) { + BOOL enableUnhandledCPPExceptions = + [experiments[@"enableUnhandledCPPExceptionsV2"] boolValue]; + [RNSentryExperimentalOptions setEnableUnhandledCPPExceptionsV2:enableUnhandledCPPExceptions + sentryOptions:sentryOptions]; + } + + return sentryOptions; +} + ++ (NSString *_Nullable)getURLFromDSN:(NSString *)dsn +{ + NSURL *url = [NSURL URLWithString:dsn]; + if (!url) { + return nil; + } + return [NSString stringWithFormat:@"%@://%@", url.scheme, url.host]; +} + ++ (void)setupWithDictionary:(NSDictionary *_Nonnull)options + error:(NSError *_Nonnull *_Nonnull)errorPointer +{ + SentryOptions *sentryOptions = [self createOptionsWithDictionary:options + error:errorPointer]; + if (!options) { + return; + } + + NSString *sdkVersion = [PrivateSentrySDKOnly getSdkVersionString]; + [PrivateSentrySDKOnly setSdkName:NATIVE_SDK_NAME andVersionString:sdkVersion]; + [PrivateSentrySDKOnly addSdkPackage:REACT_NATIVE_SDK_PACKAGE_NAME + version:REACT_NATIVE_SDK_PACKAGE_VERSION]; + + [SentrySDKWrapper startWithOptions:sentryOptions]; +} + ++ (BOOL)debug +{ + return PrivateSentrySDKOnly.options.debug; +} + ++ (NSString *)releaseName +{ + return PrivateSentrySDKOnly.options.releaseName; +} + ++ (BOOL)enableAutoSessionTracking +{ + return PrivateSentrySDKOnly.options.enableAutoSessionTracking; +} + ++ (BOOL)enableWatchdogTerminationTracking +{ + return PrivateSentrySDKOnly.options.enableWatchdogTerminationTracking; +} + @end