Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ios): Don't pass enableTracing from RN to sentry-cocoa options #3042

Merged
merged 10 commits into from
May 5, 2023
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixes

- Fix `event.origin` and `event.environment` on unhandled exception ([#3041](https://github.com/getsentry/sentry-react-native/pull/3041))
- Don't pass `enableTracing` from RN to `sentry-cocoa` options ([#3042](https://github.com/getsentry/sentry-react-native/pull/3042))

## 5.4.1

Expand Down
25 changes: 13 additions & 12 deletions RNSentryTester/RNSentryTesterTests/RNSentry+initNativeSdk.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ - (void)testCreateOptionsWithDictionaryRemovesPerformanceProperties
NSDictionary *_Nonnull mockedReactNativeDictionary = @{
@"dsn": @"https://[email protected]/123456",
@"beforeSend": @"will_be_overwritten",
@"enableNativeCrashHandling": @YES,

@"tracesSampleRate": @1,
@"tracesSampler": ^(SentrySamplingContext *_Nonnull samplingContext) {
return @1;
},
@"enableTracing": @YES,
};
SentryOptions* actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary error:&error];

Expand All @@ -28,6 +31,7 @@ - (void)testCreateOptionsWithDictionaryRemovesPerformanceProperties
XCTAssertNotNil(actualOptions.beforeSend, @"Before send is overwriten by the native RNSentry implementation");
XCTAssertEqual(actualOptions.tracesSampleRate, nil, @"Traces sample rate should not be passed to native");
XCTAssertEqual(actualOptions.tracesSampler, nil, @"Traces sampler should not be passed to native");
XCTAssertEqual(actualOptions.enableTracing, false, @"EnableTracing should not be passed to native");
}

- (void)testCreateOptionsWithDictionaryNativeCrashHandlingDefault
Expand All @@ -44,7 +48,7 @@ - (void)testCreateOptionsWithDictionaryNativeCrashHandlingDefault
XCTAssertEqual([actualOptions.integrations containsObject:@"SentryCrashIntegration"], true, @"Did not set native crash handling");
}

- (void)testCreateOptionsWithDictionaryPerformanceTrackingDefault
- (void)testCreateOptionsWithDictionaryAutoPerformanceTracingDefault
{
RNSentry * rnSentry = [[RNSentry alloc] init];
NSError* error = nil;
Expand Down Expand Up @@ -73,15 +77,14 @@ - (void)testCreateOptionsWithDictionaryNativeCrashHandlingEnabled
XCTAssertEqual([actualOptions.integrations containsObject:@"SentryCrashIntegration"], true, @"Did not set native crash handling");
}

- (void)testCreateOptionsWithDictionaryPerformanceTrackingEnabled
- (void)testCreateOptionsWithDictionaryAutoPerformanceTracingEnabled
{
RNSentry * rnSentry = [[RNSentry alloc] init];
NSError* error = nil;

NSDictionary *_Nonnull mockedReactNativeDictionary = @{
@"dsn": @"https://[email protected]/123456",
@"enableAutoPerformanceTracing": @YES,

};
SentryOptions* actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary error:&error];
XCTAssertNotNil(actualOptions, @"Did not create sentry options");
Expand All @@ -97,23 +100,21 @@ - (void)testCreateOptionsWithDictionaryNativeCrashHandlingDisabled
NSDictionary *_Nonnull mockedReactNativeDictionary = @{
@"dsn": @"https://[email protected]/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
- (void)testCreateOptionsWithDictionaryAutoPerformanceTracingDisabled
{
RNSentry * rnSentry = [[RNSentry alloc] init];
NSError* error = nil;

NSDictionary *_Nonnull mockedReactNativeDictionary = @{
@"dsn": @"https://[email protected]/123456",
@"enableAutoPerformanceTracing": @NO,

};
SentryOptions* actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary error:&error];
XCTAssertNotNil(actualOptions, @"Did not create sentry options");
Expand All @@ -127,7 +128,7 @@ - (void)testPassesErrorOnWrongDsn
NSError* error = nil;

NSDictionary *_Nonnull mockedReactNativeDictionary = @{
@"dsn": @"not_a_valid_dsn"
@"dsn": @"not_a_valid_dsn",
};
SentryOptions* actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary error:&error];

Expand All @@ -140,7 +141,7 @@ - (void)testEventFromSentryCocoaReactNativeHasOriginAndEnvironmentTags
RNSentry* rnSentry = [[RNSentry alloc] init];
SentryEvent* testEvent = [[SentryEvent alloc] init];
testEvent.sdk = @{
@"name": @"sentry.cocoa.react-native"
@"name": @"sentry.cocoa.react-native",
};

[rnSentry setEventOriginTag: testEvent];
Expand All @@ -154,11 +155,11 @@ - (void)testEventFromSentryReactNativeOriginAndEnvironmentTagsAreOverwritten
RNSentry* rnSentry = [[RNSentry alloc] init];
SentryEvent* testEvent = [[SentryEvent alloc] init];
testEvent.sdk = @{
@"name": @"sentry.cocoa.react-native"
@"name": @"sentry.cocoa.react-native",
};
testEvent.tags = @{
@"event.origin": @"testEventOriginTag",
@"event.environment": @"testEventEnvironmentTag"
@"event.environment": @"testEventEnvironmentTag",
};

[rnSentry setEventOriginTag: testEvent];
Expand Down
1 change: 1 addition & 0 deletions ios/RNSentry.mm
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ - (SentryOptions *_Nullable)createOptionsWithDictionary:(NSDictionary *_Nonnull)
// The user could tho initialize the SDK manually and set themselves.
[mutableOptions removeObjectForKey:@"tracesSampleRate"];
[mutableOptions removeObjectForKey:@"tracesSampler"];
[mutableOptions removeObjectForKey:@"enableTracing"];

SentryOptions *sentryOptions = [[SentryOptions alloc] initWithDict:mutableOptions didFailWithError:errorPointer];
if (*errorPointer != nil) {
Expand Down