-
-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Exclude Dev Server and Sentry Dsn request from Breadcrumbs (
#4240) * Adds breadcrumb origin in RNSentryBreadcrumb dictionary parsing * Use 8.38.0-beta.1 Cocoa SDK that has the new origin field * Adds changelog * Fixes sentry-java breaking changes * Adds origin native tests * Adds Capture exception with breadcrumb in the sample * Set react native as event origin * Filter out events with react-native origin from the native layer * Merge event breadcrumbs with native context * Lint: removes empty line * Use predicate to filter breadcrumbs * Respect max breadcrumbs limit * Updates changelog * Update test names * Fixes lint issue * Filter out DevServer and DSN related breadcrumbs * Adds changelog * Keep the last maxBreadcrumbs (default 100) when merging native and js breadcrumbs * Use client from function parameter * Refactor and test RNSentryModuleImpl.fetchNativeDeviceContexts (#4253) * Refactor fetchNativeDeviceContexts for testability * Test fetchNativeDeviceContexts * Adds new line at the end * Revert "Filter out DevServer and DSN related breadcrumbs" This reverts commit 87bdc77. * Passes development server url as an option to the native sdks * Filter out Dev Server and Sentry Dsn breadcrumbs on Android * Filter out Dev Server and Sentry Dsn breadcrumbs on iOS * Filter out Dev Server and Sentry Dsn breadcrumbs on JS * Adds Java tests * Adds Cocoa tests * Adds JS tests * Sets correct spacing in import Co-authored-by: LucasZF <[email protected]> * Fixes changelog typo Co-authored-by: LucasZF <[email protected]> * Handles undefined dev server urls Co-authored-by: LucasZF <[email protected]> * Handles undefined dsns * Adds tests for undefined dev servers and dsns * Handles undefined dev server urls in native code * Updates test cases * Uses the url from the passed dsn to filter breadcrumbs * Handles nil dsn though this state should never be reached due to SentryOptions validation * Use startsWith to check url matching Co-authored-by: LucasZF <[email protected]> * Check url with prefix instead of contains for efficiency * Fix comment typo Co-authored-by: LucasZF <[email protected]> * Fix comment typo Co-authored-by: LucasZF <[email protected]> * Fix comment typo Co-authored-by: LucasZF <[email protected]> * Update CHANGELOG.md * Safely parses dsn url * Adds test case for url exception --------- Co-authored-by: LucasZF <[email protected]> Co-authored-by: Krystof Woldrich <[email protected]>
- Loading branch information
1 parent
fa2ef81
commit 112c4f8
Showing
10 changed files
with
495 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,12 +8,14 @@ import com.facebook.react.bridge.Promise | |
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.bridge.WritableMap | ||
import com.facebook.react.common.JavascriptException | ||
import io.sentry.Breadcrumb | ||
import io.sentry.ILogger | ||
import io.sentry.SentryLevel | ||
import io.sentry.android.core.SentryAndroidOptions | ||
import org.junit.After | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertNull | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
@@ -134,4 +136,109 @@ class RNSentryModuleImplTest { | |
module.getSentryAndroidOptions(actualOptions, JavaOnlyMap.of(), logger) | ||
assertTrue(actualOptions.ignoredExceptionsForType.contains(JavascriptException::class.java)) | ||
} | ||
|
||
@Test | ||
fun `beforeBreadcrumb callback filters out Sentry DSN requests breadcrumbs`() { | ||
val options = SentryAndroidOptions() | ||
val rnOptions = JavaOnlyMap.of( | ||
"dsn", "https://[email protected]/1234567", | ||
"devServerUrl", "http://localhost:8081", | ||
) | ||
module.getSentryAndroidOptions(options, rnOptions, logger) | ||
|
||
val breadcrumb = Breadcrumb().apply { | ||
type = "http" | ||
setData("url", "https://def.ingest.sentry.io/1234567") | ||
} | ||
|
||
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock()) | ||
|
||
assertNull("Breadcrumb should be filtered out", result) | ||
} | ||
|
||
@Test | ||
fun `beforeBreadcrumb callback filters out dev server breadcrumbs`() { | ||
val mockDevServerUrl = "http://localhost:8081" | ||
val options = SentryAndroidOptions() | ||
val rnOptions = JavaOnlyMap.of( | ||
"dsn", "https://[email protected]/1234567", | ||
"devServerUrl", mockDevServerUrl, | ||
) | ||
module.getSentryAndroidOptions(options, rnOptions, logger) | ||
|
||
val breadcrumb = Breadcrumb().apply { | ||
type = "http" | ||
setData("url", mockDevServerUrl) | ||
} | ||
|
||
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock()) | ||
|
||
assertNull("Breadcrumb should be filtered out", result) | ||
} | ||
|
||
@Test | ||
fun `beforeBreadcrumb callback does not filter out non dev server or dsn breadcrumbs`() { | ||
val options = SentryAndroidOptions() | ||
val rnOptions = JavaOnlyMap.of( | ||
"dsn", "https://[email protected]/1234567", | ||
"devServerUrl", "http://localhost:8081", | ||
) | ||
module.getSentryAndroidOptions(options, rnOptions, logger) | ||
|
||
val breadcrumb = Breadcrumb().apply { | ||
type = "http" | ||
setData("url", "http://testurl.com/service") | ||
} | ||
|
||
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock()) | ||
|
||
assertEquals(breadcrumb, result) | ||
} | ||
|
||
@Test | ||
fun `the breadcrumb is not filtered out when the dev server url and dsn are not passed`() { | ||
val options = SentryAndroidOptions() | ||
module.getSentryAndroidOptions(options, JavaOnlyMap(), logger) | ||
|
||
val breadcrumb = Breadcrumb().apply { | ||
type = "http" | ||
setData("url", "http://testurl.com/service") | ||
} | ||
|
||
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock()) | ||
|
||
assertEquals(breadcrumb, result) | ||
} | ||
|
||
@Test | ||
fun `the breadcrumb is not filtered out when the dev server url is not passed and the dsn does not match`() { | ||
val options = SentryAndroidOptions() | ||
val rnOptions = JavaOnlyMap.of("dsn", "https://[email protected]/1234567") | ||
module.getSentryAndroidOptions(options, rnOptions, logger) | ||
|
||
val breadcrumb = Breadcrumb().apply { | ||
type = "http" | ||
setData("url", "http://testurl.com/service") | ||
} | ||
|
||
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock()) | ||
|
||
assertEquals(breadcrumb, result) | ||
} | ||
|
||
@Test | ||
fun `the breadcrumb is not filtered out when the dev server url does not match and the dsn is not passed`() { | ||
val options = SentryAndroidOptions() | ||
val rnOptions = JavaOnlyMap.of("devServerUrl", "http://localhost:8081") | ||
module.getSentryAndroidOptions(options, rnOptions, logger) | ||
|
||
val breadcrumb = Breadcrumb().apply { | ||
type = "http" | ||
setData("url", "http://testurl.com/service") | ||
} | ||
|
||
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock()) | ||
|
||
assertEquals(breadcrumb, result) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -238,6 +238,85 @@ - (void)testPassesErrorOnWrongDsn | |
XCTAssertNotNil(error, @"Did not created error on invalid dsn"); | ||
} | ||
|
||
- (void)testBeforeBreadcrumbsCallbackFiltersOutSentryDsnRequestBreadcrumbs | ||
{ | ||
RNSentry *rnSentry = [[RNSentry alloc] init]; | ||
NSError *error = nil; | ||
|
||
NSDictionary *_Nonnull mockedDictionary = @{ | ||
@"dsn" : @"https://[email protected]/1234567", | ||
@"devServerUrl" : @"http://localhost:8081" | ||
}; | ||
SentryOptions *options = [rnSentry createOptionsWithDictionary:mockedDictionary error:&error]; | ||
|
||
SentryBreadcrumb *breadcrumb = [[SentryBreadcrumb alloc] init]; | ||
breadcrumb.type = @"http"; | ||
breadcrumb.data = @{ @"url" : @"https://def.ingest.sentry.io/1234567" }; | ||
|
||
SentryBreadcrumb *result = options.beforeBreadcrumb(breadcrumb); | ||
|
||
XCTAssertNil(result, @"Breadcrumb should be filtered out"); | ||
} | ||
|
||
- (void)testBeforeBreadcrumbsCallbackFiltersOutDevServerRequestBreadcrumbs | ||
{ | ||
RNSentry *rnSentry = [[RNSentry alloc] init]; | ||
NSError *error = nil; | ||
|
||
NSString *mockDevServer = @"http://localhost:8081"; | ||
|
||
NSDictionary *_Nonnull mockedDictionary = | ||
@{ @"dsn" : @"https://[email protected]/1234567", @"devServerUrl" : mockDevServer }; | ||
SentryOptions *options = [rnSentry createOptionsWithDictionary:mockedDictionary error:&error]; | ||
|
||
SentryBreadcrumb *breadcrumb = [[SentryBreadcrumb alloc] init]; | ||
breadcrumb.type = @"http"; | ||
breadcrumb.data = @{ @"url" : mockDevServer }; | ||
|
||
SentryBreadcrumb *result = options.beforeBreadcrumb(breadcrumb); | ||
|
||
XCTAssertNil(result, @"Breadcrumb should be filtered out"); | ||
} | ||
|
||
- (void)testBeforeBreadcrumbsCallbackDoesNotFiltersOutNonDevServerOrDsnRequestBreadcrumbs | ||
{ | ||
RNSentry *rnSentry = [[RNSentry alloc] init]; | ||
NSError *error = nil; | ||
|
||
NSDictionary *_Nonnull mockedDictionary = @{ | ||
@"dsn" : @"https://[email protected]/1234567", | ||
@"devServerUrl" : @"http://localhost:8081" | ||
}; | ||
SentryOptions *options = [rnSentry createOptionsWithDictionary:mockedDictionary error:&error]; | ||
|
||
SentryBreadcrumb *breadcrumb = [[SentryBreadcrumb alloc] init]; | ||
breadcrumb.type = @"http"; | ||
breadcrumb.data = @{ @"url" : @"http://testurl.com/service" }; | ||
|
||
SentryBreadcrumb *result = options.beforeBreadcrumb(breadcrumb); | ||
|
||
XCTAssertEqual(breadcrumb, result); | ||
} | ||
|
||
- (void)testBeforeBreadcrumbsCallbackKeepsBreadcrumbWhenDevServerUrlIsNotPassedAndDsnDoesNotMatch | ||
{ | ||
RNSentry *rnSentry = [[RNSentry alloc] init]; | ||
NSError *error = nil; | ||
|
||
NSDictionary *_Nonnull mockedDictionary = @{ // dsn is always validated in SentryOptions initialization | ||
@"dsn" : @"https://[email protected]/1234567" | ||
}; | ||
SentryOptions *options = [rnSentry createOptionsWithDictionary:mockedDictionary error:&error]; | ||
|
||
SentryBreadcrumb *breadcrumb = [[SentryBreadcrumb alloc] init]; | ||
breadcrumb.type = @"http"; | ||
breadcrumb.data = @{ @"url" : @"http://testurl.com/service" }; | ||
|
||
SentryBreadcrumb *result = options.beforeBreadcrumb(breadcrumb); | ||
|
||
XCTAssertEqual(breadcrumb, result); | ||
} | ||
|
||
- (void)testEventFromSentryCocoaReactNativeHasOriginAndEnvironmentTags | ||
{ | ||
RNSentry *rnSentry = [[RNSentry alloc] init]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.