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

feat(core): Exclude Dev Server and Sentry Dsn request from Breadcrumbs #4240

Merged
merged 62 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
494a619
Adds breadcrumb origin in RNSentryBreadcrumb dictionary parsing
antonis Sep 27, 2024
cc0b364
Merge branch 'main' into antonis/add-breadcrumb-origin
antonis Oct 8, 2024
a636be5
Use 8.38.0-beta.1 Cocoa SDK that has the new origin field
antonis Oct 8, 2024
522897a
Merge branch 'main' into antonis/add-breadcrumb-origin
antonis Oct 9, 2024
197f863
Adds changelog
antonis Oct 9, 2024
9bee5c9
Fixes sentry-java breaking changes
antonis Oct 9, 2024
6268a43
Merge branch 'main' into antonis/add-breadcrumb-origin
antonis Oct 10, 2024
6095218
Merge branch 'main' into antonis/add-breadcrumb-origin
antonis Oct 11, 2024
0e43c5d
Merge branch 'main' into antonis/add-breadcrumb-origin
antonis Oct 15, 2024
8832cf9
Merge branch 'main' into antonis/add-breadcrumb-origin
antonis Oct 15, 2024
7a108ee
Merge branch 'main' into antonis/add-breadcrumb-origin
antonis Oct 16, 2024
aff18bf
Merge branch 'main' into antonis/add-breadcrumb-origin
antonis Oct 23, 2024
611cd97
Adds origin native tests
antonis Oct 23, 2024
37553f2
Adds Capture exception with breadcrumb in the sample
antonis Oct 23, 2024
24a527b
Set react native as event origin
antonis Oct 28, 2024
fabf052
Filter out events with react-native origin from the native layer
antonis Oct 28, 2024
d0b1633
Merge event breadcrumbs with native context
antonis Oct 28, 2024
5d2711c
Lint: removes empty line
antonis Oct 28, 2024
fb0057d
Merge branch 'main' into antonis/add-breadcrumb-origin
antonis Oct 31, 2024
78c24f0
Use predicate to filter breadcrumbs
antonis Oct 31, 2024
6fcd93d
Respect max breadcrumbs limit
antonis Oct 31, 2024
80add4f
Merge branch 'main' into antonis/add-breadcrumb-origin
antonis Nov 1, 2024
44e02ec
Updates changelog
antonis Nov 1, 2024
a2d29de
Update test names
antonis Nov 1, 2024
52c9e54
Merge branch 'main' into antonis/add-breadcrumb-origin
antonis Nov 6, 2024
81a11c3
Fixes lint issue
antonis Nov 6, 2024
f828fc7
Merge branch 'main' into antonis/add-breadcrumb-origin
antonis Nov 6, 2024
87bdc77
Filter out DevServer and DSN related breadcrumbs
antonis Nov 6, 2024
2d68620
Adds changelog
antonis Nov 6, 2024
67bd716
Merge branch 'main' into antonis/add-breadcrumb-origin
antonis Nov 7, 2024
c4246d7
Keep the last maxBreadcrumbs (default 100) when merging native and js…
antonis Nov 7, 2024
17e2201
Use client from function parameter
antonis Nov 11, 2024
fef2173
Merge branch 'main' into antonis/add-breadcrumb-origin
antonis Nov 11, 2024
76285fa
Refactor and test RNSentryModuleImpl.fetchNativeDeviceContexts (#4253)
antonis Nov 11, 2024
ff7ca33
Revert "Filter out DevServer and DSN related breadcrumbs"
antonis Nov 12, 2024
5121c83
Merge branch 'antonis/add-breadcrumb-origin' into antonis/3105-exclud…
antonis Nov 12, 2024
3811047
Passes development server url as an option to the native sdks
antonis Nov 12, 2024
c3da88b
Filter out Dev Server and Sentry Dsn breadcrumbs on Android
antonis Nov 12, 2024
d67de6c
Filter out Dev Server and Sentry Dsn breadcrumbs on iOS
antonis Nov 12, 2024
6ddc665
Filter out Dev Server and Sentry Dsn breadcrumbs on JS
antonis Nov 12, 2024
af02c03
Adds Java tests
antonis Nov 13, 2024
7ae568a
Adds Cocoa tests
antonis Nov 13, 2024
575821e
Adds JS tests
antonis Nov 13, 2024
efa3871
Sets correct spacing in import
antonis Nov 14, 2024
709b8df
Fixes changelog typo
antonis Nov 14, 2024
fef13ca
Handles undefined dev server urls
antonis Nov 14, 2024
96f3b5d
Handles undefined dsns
antonis Nov 14, 2024
ccaa502
Adds tests for undefined dev servers and dsns
antonis Nov 14, 2024
06ff84c
Handles undefined dev server urls in native code
antonis Nov 14, 2024
a213332
Updates test cases
antonis Nov 14, 2024
a69d5e8
Uses the url from the passed dsn to filter breadcrumbs
antonis Nov 14, 2024
e451c06
Handles nil dsn though this state should never be reached due to Sent…
antonis Nov 14, 2024
eae86ad
Use startsWith to check url matching
antonis Nov 15, 2024
c05c3c2
Check url with prefix instead of contains for efficiency
antonis Nov 15, 2024
48034dc
Fix comment typo
antonis Nov 15, 2024
3381a9e
Fix comment typo
antonis Nov 15, 2024
1f7891e
Fix comment typo
antonis Nov 15, 2024
5f23d48
Merge branch 'main' into antonis/3105-exclude-dsn-and-devserver
krystofwoldrich Nov 18, 2024
848aaa3
Update CHANGELOG.md
krystofwoldrich Nov 18, 2024
41ac85a
Safely parses dsn url
antonis Nov 18, 2024
bfc7c33
Merge branch 'main' into antonis/3105-exclude-dsn-and-devserver
antonis Nov 18, 2024
b6191be
Adds test case for url exception
antonis Nov 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

### Fixes

- Excludes Dev Server and Sentry Dsn requests from Breadcrumbs ([#4240](https://github.com/getsentry/sentry-react-native/pull/4240))
- Prevents exception capture context from being overwritten by native scope sync ([#4124](https://github.com/getsentry/sentry-react-native/pull/4124))
- Ignore JavascriptException to filter out obfuscated duplicate JS Errors on Android ([#4232](https://github.com/getsentry/sentry-react-native/pull/4232))
- Skips ignoring require cycle logs for RN 0.70 or newer ([#4214](https://github.com/getsentry/sentry-react-native/pull/4214))
- Enhanced accuracy of time-to-display spans. ([#4189](https://github.com/getsentry/sentry-react-native/pull/4189))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package io.sentry.react

import android.content.Context
import androidx.test.platform.app.InstrumentationRegistry
import com.facebook.react.bridge.PromiseImpl
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.WritableMap
import com.facebook.soloader.SoLoader
import io.sentry.Breadcrumb
import io.sentry.Scope
import io.sentry.SentryOptions
import io.sentry.android.core.SentryAndroidOptions
import org.junit.Assert.assertEquals
import org.junit.Assert.fail
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4

@RunWith(JUnit4::class)
class RNSentryModuleImplTest {

private lateinit var module: RNSentryModuleImpl
private lateinit var context: Context

@Before
fun setUp() {
context = InstrumentationRegistry.getInstrumentation().targetContext
SoLoader.init(context, false)
val reactContext = ReactApplicationContext(context)
module = RNSentryModuleImpl(reactContext)
}

@Test
fun fetchNativeDeviceContextsWithNullContext() {
val options = SentryAndroidOptions()
val scope = Scope(options)
val promise = PromiseImpl({
assertEquals(1, it.size)
assertEquals(null, it[0])
}, {
fail("Promise was rejected unexpectedly")
})
module.fetchNativeDeviceContexts(promise, options, null, scope)
}

@Test
fun fetchNativeDeviceContextsWithInvalidSentryOptions() {
class NotAndroidSentryOptions : SentryOptions()

val options = NotAndroidSentryOptions()
val scope = Scope(options)
val promise = PromiseImpl({
assertEquals(1, it.size)
assertEquals(null, it[0])
}, {
fail("Promise was rejected unexpectedly")
})
module.fetchNativeDeviceContexts(promise, options, context, scope)
}

@Test
fun fetchNativeDeviceContextsFiltersBreadcrumbs() {
val options = SentryAndroidOptions().apply { maxBreadcrumbs = 5 }
val scope = Scope(options)
scope.addBreadcrumb(Breadcrumb("Breadcrumb1-RN").apply { origin = "react-native" })
scope.addBreadcrumb(Breadcrumb("Breadcrumb2-Native"))
scope.addBreadcrumb(Breadcrumb("Breadcrumb3-Native").apply { origin = "java" })
scope.addBreadcrumb(Breadcrumb("Breadcrumb2-RN").apply { origin = "react-native" })
scope.addBreadcrumb(Breadcrumb("Breadcrumb2-RN").apply { origin = "react-native" })

val promise = PromiseImpl({
assertEquals(1, it.size)
assertEquals(true, it[0] is WritableMap)
val actual = it[0] as WritableMap
val breadcrumbs = actual.getArray("breadcrumbs")
assertEquals(2, breadcrumbs?.size())
assertEquals("Breadcrumb2-Native", breadcrumbs?.getMap(0)?.getString("message"))
assertEquals("Breadcrumb3-Native", breadcrumbs?.getMap(1)?.getString("message"))
}, {
fail("Promise was rejected unexpectedly")
})

module.fetchNativeDeviceContexts(promise, options, context, scope)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.sentry.rnsentryandroidtester

import com.facebook.react.bridge.JavaOnlyMap
import io.sentry.SentryLevel
import io.sentry.react.RNSentryBreadcrumb
import junit.framework.TestCase.assertEquals
import org.junit.Test
Expand All @@ -10,6 +11,38 @@ import org.junit.runners.JUnit4
@RunWith(JUnit4::class)
class RNSentryBreadcrumbTest {

@Test
fun generatesSentryBreadcrumbFromMap() {
val testData = JavaOnlyMap.of(
"test", "data",
)
val map = JavaOnlyMap.of(
"level", "error",
"category", "testCategory",
"origin", "testOrigin",
"type", "testType",
"message", "testMessage",
"data", testData,
)
val actual = RNSentryBreadcrumb.fromMap(map)
assertEquals(SentryLevel.ERROR, actual.level)
assertEquals("testCategory", actual.category)
assertEquals("testOrigin", actual.origin)
assertEquals("testType", actual.type)
assertEquals("testMessage", actual.message)
assertEquals(testData.toHashMap(), actual.data)
}

@Test
fun reactNativeForMissingOrigin() {
val map = JavaOnlyMap.of(
"message", "testMessage",
)
val actual = RNSentryBreadcrumb.fromMap(map)
assertEquals("testMessage", actual.message)
assertEquals("react-native", actual.origin)
}

@Test
fun nullForMissingCategory() {
val map = JavaOnlyMap.of()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
33AFDFED2B8D14B300AAB120 /* RNSentryFramesTrackerListenerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33AFDFEC2B8D14B300AAB120 /* RNSentryFramesTrackerListenerTests.m */; };
33AFDFF12B8D15E500AAB120 /* RNSentryDependencyContainerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33AFDFF02B8D15E500AAB120 /* RNSentryDependencyContainerTests.m */; };
33F58AD02977037D008F60EA /* RNSentryTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 33F58ACF2977037D008F60EA /* RNSentryTests.mm */; };
AEFB00422CC90C4B00EC8A9A /* RNSentryBreadcrumbTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3360843C2C340C76008CC412 /* RNSentryBreadcrumbTests.swift */; };
B5859A50A3E865EF5E61465A /* libPods-RNSentryCocoaTesterTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 650CB718ACFBD05609BF2126 /* libPods-RNSentryCocoaTesterTests.a */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -221,6 +222,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
AEFB00422CC90C4B00EC8A9A /* RNSentryBreadcrumbTests.swift in Sources */,
332D33472CDBDBB600547D76 /* RNSentryReplayOptionsTests.swift in Sources */,
33AFDFF12B8D15E500AAB120 /* RNSentryDependencyContainerTests.m in Sources */,
336084392C32E382008CC412 /* RNSentryReplayBreadcrumbConverterTests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import XCTest
import Sentry

class RNSentryBreadcrumbTests: XCTestCase {
final class RNSentryBreadcrumbTests: XCTestCase {

func testGeneratesSentryBreadcrumbFromNSDictionary() {
let actualCrumb = RNSentryBreadcrumb.from([
"level": "error",
"category": "testCategory",
"origin": "testOrigin",
"type": "testType",
"message": "testMessage",
"data": [
Expand All @@ -16,11 +17,29 @@ class RNSentryBreadcrumbTests: XCTestCase {

XCTAssertEqual(actualCrumb!.level, SentryLevel.error)
XCTAssertEqual(actualCrumb!.category, "testCategory")
XCTAssertEqual(actualCrumb!.origin, "testOrigin")
XCTAssertEqual(actualCrumb!.type, "testType")
XCTAssertEqual(actualCrumb!.message, "testMessage")
XCTAssertEqual((actualCrumb!.data)!["test"] as! String, "data")
}

func testUsesReactNativeAsDefaultOrigin() {
let actualCrumb = RNSentryBreadcrumb.from([
"message": "testMessage"
])

XCTAssertEqual(actualCrumb!.origin, "react-native")
}

func testKeepsOriginIfSet() {
let actualCrumb = RNSentryBreadcrumb.from([
"message": "testMessage",
"origin": "someOrigin"
])

XCTAssertEqual(actualCrumb!.origin, "someOrigin")
}

func testUsesInfoAsDefaultSentryLevel() {
let actualCrumb = RNSentryBreadcrumb.from([
"message": "testMessage"
Expand Down
Loading
Loading