Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
bf7c762
Extract Android SDK Init
antonis Jan 14, 2025
897d918
Update tests
antonis Jan 14, 2025
e06e6bb
Adds changelog
antonis Jan 14, 2025
903fc55
Fix lint issues
antonis Jan 14, 2025
739ad30
Rename RNSentryStart instance for clarity
antonis Jan 15, 2025
0f06266
WIP: Init with hardcoded json string
antonis Jan 15, 2025
42c32ec
Adds changelog
antonis Jan 15, 2025
a98bd88
Expose only a Java Map parameter in the startWithOptions
antonis Jan 15, 2025
1da8ca3
Fix lint issue
antonis Jan 15, 2025
be6b815
Convert RNSentrySDK to utility class
antonis Jan 15, 2025
2163884
Initialise from assets json file
antonis Jan 15, 2025
8454727
Copy configuration json in the android assets folder before building
antonis Jan 16, 2025
1c31e21
Adds map converter tests
antonis Jan 16, 2025
ff20ed9
Disable by default in the sample
antonis Jan 16, 2025
6509ada
Cleanup sentry.options.json from assets after the build
antonis Jan 16, 2025
dcb7e2e
Converts RNSentryStart to utility class
antonis Jan 20, 2025
99410e9
Merge branch 'main' into antonis/extract-android-sdk-init
antonis Jan 20, 2025
06b1def
Merge branch 'antonis/extract-android-sdk-init' into antonis/init-fro…
antonis Jan 20, 2025
f96e2d1
Align with merged convertion of RNSentryStart to utility class
antonis Jan 20, 2025
7788b81
Align with Sentry Android naming
antonis Jan 20, 2025
25d142a
Override json configuration with passed Android configuration
antonis Jan 20, 2025
cedd24a
Fix comment
antonis Jan 20, 2025
3d41a98
Merge branch 'main' into antonis/extract-android-sdk-init
antonis Jan 21, 2025
0de5bfa
Merge branch 'antonis/extract-android-sdk-init' into antonis/init-fro…
antonis Jan 21, 2025
d909ed4
Update changelog
antonis Jan 21, 2025
c26ca00
Merge branch 'capture-app-start-errors' into antonis/init-from-json
antonis Jan 22, 2025
dfb12d0
Fix changelog
antonis Jan 22, 2025
108c625
Merge branch 'capture-app-start-errors' into antonis/init-from-json
antonis Jan 23, 2025
710f1a0
Use RNSentryJsonConverter.convertToWritable
antonis Jan 23, 2025
7469dc8
Move getOptionsFromConfigurationFile in a utility class
antonis Jan 23, 2025
e266ae1
Handle initialisation errors
antonis Jan 23, 2025
7522fce
Remove beforeSend initialisation option
antonis Jan 24, 2025
5ebe8fb
Lower access level were possible
antonis Jan 24, 2025
b6a36a1
Allow combining more than two configurations
antonis Jan 24, 2025
8e87539
Add default and final configuration
antonis Jan 24, 2025
e0264ef
Add a flag to disable reading from the file
antonis Jan 24, 2025
927a003
Adds RNSentrySDK tests
antonis Jan 24, 2025
007a9d9
Fix lint issue
antonis Jan 24, 2025
32bc0a7
Update changelog
antonis Jan 24, 2025
8fc973f
Updates javadoc
antonis Jan 24, 2025
58e6e9c
Merge branch 'capture-app-start-errors' into antonis/init-from-json
krystofwoldrich Feb 3, 2025
821fef9
Ignore JavascriptException by default
antonis Feb 3, 2025
43b26db
Move SDK name and version to react defaults
antonis Feb 3, 2025
d2fd58f
Set current activity in defaults
antonis Feb 3, 2025
5b9665a
Defaults override file/rn configuration
antonis Feb 3, 2025
2b7a319
Add tests for defaults and finals
antonis Feb 4, 2025
d236c82
Allow passing sdk init function
antonis Feb 4, 2025
ced915d
Add tests verifying defaults, finals and overriding behavior
antonis Feb 4, 2025
1c96a27
Revert "Allow passing sdk init function"
antonis Feb 4, 2025
8a87565
Use Sentry.getCurrentHub().options to check the initialised options
antonis Feb 4, 2025
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

- Rename `navigation.processing` span to more expressive `Navigation dispatch to screen A mounted/navigation cancelled` ([#4423](https://github.com/getsentry/sentry-react-native/pull/4423))
- Add RN SDK package to `sdk.packages` for Cocoa ([#4381](https://github.com/getsentry/sentry-react-native/pull/4381))
- Add experimental initialization using `sentry.options.json` and `RNSentrySDK.startWithOptions` method for Android ([#4451](https://github.com/getsentry/sentry-react-native/pull/4451))

### Dependencies

Expand All @@ -26,6 +27,10 @@
- [changelog](https://github.com/getsentry/sentry-javascript/blob/develop/CHANGELOG.md#8480)
- [diff](https://github.com/getsentry/sentry-javascript/compare/8.47.0...8.48.0)

### Internal

- Extract Android native initialization to standalone structures ([#4445](https://github.com/getsentry/sentry-react-native/pull/4445))

## 6.5.0

### Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import android.content.Context
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.JavaOnlyMap
import com.facebook.soloader.SoLoader
import io.sentry.react.RNSentryMapConverter
import org.json.JSONObject
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -359,4 +363,40 @@ class MapConverterTest {

assertEquals(actual, expectedMap1)
}

@Test
fun testJsonObjectToReadableMap() {
val json =
JSONObject().apply {
put("stringKey", "stringValue")
put("booleanKey", true)
put("intKey", 123)
}

val result = RNSentryMapConverter.jsonObjectToReadableMap(json)

assertNotNull(result)
assertTrue(result is JavaOnlyMap)
assertEquals("stringValue", result.getString("stringKey"))
assertEquals(true, result.getBoolean("booleanKey"))
assertEquals(123, result.getInt("intKey"))
}

@Test
fun testMapToReadableMap() {
val map =
mapOf(
"stringKey" to "stringValue",
"booleanKey" to true,
"intKey" to 123,
)

val result = RNSentryMapConverter.mapToReadableMap(map)

assertNotNull(result)
assertTrue(result is JavaOnlyMap)
assertEquals("stringValue", result.getString("stringKey"))
assertEquals(true, result.getBoolean("booleanKey"))
assertEquals(123, result.getInt("intKey"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@ package io.sentry.react
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.JavaOnlyMap
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
import org.junit.runner.RunWith
Expand Down Expand Up @@ -103,163 +96,4 @@ class RNSentryModuleImplTest {
val capturedMap = writableMapCaptor.value
assertEquals(false, capturedMap.getBoolean("has_fetched"))
}

@Test
fun `when the spotlight option is enabled, the spotlight SentryAndroidOption is set to true and the default url is used`() {
val options =
JavaOnlyMap.of(
"spotlight",
true,
"defaultSidecarUrl",
"http://localhost:8969/teststream",
)
val actualOptions = SentryAndroidOptions()
module.getSentryAndroidOptions(actualOptions, options, logger)
assert(actualOptions.isEnableSpotlight)
assertEquals("http://localhost:8969/teststream", actualOptions.spotlightConnectionUrl)
}

@Test
fun `when the spotlight url is passed, the spotlight is enabled for the given url`() {
val options = JavaOnlyMap.of("spotlight", "http://localhost:8969/teststream")
val actualOptions = SentryAndroidOptions()
module.getSentryAndroidOptions(actualOptions, options, logger)
assert(actualOptions.isEnableSpotlight)
assertEquals("http://localhost:8969/teststream", actualOptions.spotlightConnectionUrl)
}

@Test
fun `when the spotlight option is disabled, the spotlight SentryAndroidOption is set to false`() {
val options = JavaOnlyMap.of("spotlight", false)
val actualOptions = SentryAndroidOptions()
module.getSentryAndroidOptions(actualOptions, options, logger)
assertFalse(actualOptions.isEnableSpotlight)
}

@Test
fun `the JavascriptException is added to the ignoredExceptionsForType list on initialisation`() {
val actualOptions = SentryAndroidOptions()
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)
}
}
Loading
Loading