From c940e375e6ea60edde8df59fd49b1f6fd4579891 Mon Sep 17 00:00:00 2001 From: werder Date: Fri, 31 Mar 2023 12:38:13 +0200 Subject: [PATCH] fix(apple): Disable `enableNativeCrashHandling` and `enableAutoPerformanceTracing`(#2936) Co-authored-by: mwerder --- CHANGELOG.md | 7 ++ .../RNSentry+initNativeSdk.mm | 90 +++++++++++++++++++ ios/RNSentry.mm | 5 +- 3 files changed, 99 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b9cb5664a..2ab240984a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## Unreleased + +### Fixes + +- Disable `enableNativeCrashHandling` and `enableAutoPerformanceTracing` on Apple ([#2936](https://github.com/getsentry/sentry-react-native/pull/)) + - Mac Catalyst builds sucessfully + ## 5.3.0 ### Features diff --git a/RNSentryTester/RNSentryTesterTests/RNSentry+initNativeSdk.mm b/RNSentryTester/RNSentryTesterTests/RNSentry+initNativeSdk.mm index 4c7b912f80..a75b14f704 100644 --- a/RNSentryTester/RNSentryTesterTests/RNSentry+initNativeSdk.mm +++ b/RNSentryTester/RNSentryTesterTests/RNSentry+initNativeSdk.mm @@ -29,6 +29,96 @@ - (void)testCreateOptionsWithDictionaryRemovesPerformanceProperties XCTAssertEqual(actualOptions.tracesSampler, nil, @"Traces sampler should not be passed to native"); } +- (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]; + 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"); +} + +- (void)testCreateOptionsWithDictionaryPerformanceTrackingDefault +{ + 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]; + XCTAssertNotNil(actualOptions, @"Did not create sentry options"); + XCTAssertNil(error, @"Should not pass no error"); + XCTAssertEqual(actualOptions.enableAutoPerformanceTracing, true, @"Did not set Auto Performance Tracing"); +} + +- (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]; + 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"); +} + +- (void)testCreateOptionsWithDictionaryPerformanceTrackingEnabled +{ + 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]; + XCTAssertNotNil(actualOptions, @"Did not create sentry options"); + XCTAssertNil(error, @"Should not pass no error"); + XCTAssertEqual(actualOptions.enableAutoPerformanceTracing, true, @"Did not set Auto Performance Tracing"); +} + +- (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]; + 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"); +} + +- (void)testCreateOptionsWithDictionaryPerformanceTrackingDisabled +{ + 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]; + XCTAssertNotNil(actualOptions, @"Did not create sentry options"); + XCTAssertNil(error, @"Should not pass no error"); + XCTAssertEqual(actualOptions.enableAutoPerformanceTracing, false, @"Did not disable Auto Performance Tracing"); +} - (void)testPassesErrorOnWrongDsn { diff --git a/ios/RNSentry.mm b/ios/RNSentry.mm index 80db9de992..60915a3621 100644 --- a/ios/RNSentry.mm +++ b/ios/RNSentry.mm @@ -108,7 +108,7 @@ - (SentryOptions *_Nullable)createOptionsWithDictionary:(NSDictionary *_Nonnull) } if ([mutableOptions valueForKey:@"enableNativeCrashHandling"] != nil) { - BOOL enableNativeCrashHandling = (BOOL)[mutableOptions valueForKey:@"enableNativeCrashHandling"]; + BOOL enableNativeCrashHandling = [mutableOptions[@"enableNativeCrashHandling"] boolValue]; if (!enableNativeCrashHandling) { NSMutableArray *integrations = sentryOptions.integrations.mutableCopy; @@ -119,8 +119,7 @@ - (SentryOptions *_Nullable)createOptionsWithDictionary:(NSDictionary *_Nonnull) // Enable the App start and Frames tracking measurements if ([mutableOptions valueForKey:@"enableAutoPerformanceTracing"] != nil) { - BOOL enableAutoPerformanceTracing = (BOOL)[mutableOptions valueForKey:@"enableAutoPerformanceTracing"]; - + BOOL enableAutoPerformanceTracing = [mutableOptions[@"enableAutoPerformanceTracing"] boolValue]; PrivateSentrySDKOnly.appStartMeasurementHybridSDKMode = enableAutoPerformanceTracing; #if TARGET_OS_IPHONE || TARGET_OS_MACCATALYST PrivateSentrySDKOnly.framesTrackingMeasurementHybridSDKMode = enableAutoPerformanceTracing;