From 968b6b69636807464a4739a937791b74b01af02c Mon Sep 17 00:00:00 2001 From: buenaflor Date: Sat, 22 Apr 2023 03:33:05 +0200 Subject: [PATCH 1/5] add elvis operator if beforeSend invoke result is null --- .../kotlin/multiplatform/extensions/SentryOptionsExtensions.kt | 2 +- .../kotlin/multiplatform/extensions/SentryOptionsExtensions.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/SentryOptionsExtensions.kt b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/SentryOptionsExtensions.kt index c245a51e..947a7896 100644 --- a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/SentryOptionsExtensions.kt +++ b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/SentryOptionsExtensions.kt @@ -54,7 +54,7 @@ internal fun CocoaSentryOptions.applyCocoaBaseOptions(options: SentryOptions) { val modifiedEvent = event?.let { SentryEvent(it) }?.let { unwrappedEvent -> val result = options.beforeSend?.invoke(unwrappedEvent) result?.let { event.applyKmpEvent(it) } - } + } ?: event dropKotlinCrashEvent(modifiedEvent as NSExceptionSentryEvent?) as CocoaSentryEvent? } diff --git a/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/SentryOptionsExtensions.kt b/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/SentryOptionsExtensions.kt index 7275cca7..d3b1906e 100644 --- a/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/SentryOptionsExtensions.kt +++ b/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/SentryOptionsExtensions.kt @@ -46,6 +46,6 @@ internal fun JvmSentryOptions.applyJvmBaseOptions(options: SentryOptions) { setBeforeSend { jvmSentryEvent, hint -> options.beforeSend?.invoke(SentryEvent(jvmSentryEvent))?.let { jvmSentryEvent.applyKmpEvent(it) - } + } ?: jvmSentryEvent } } From 8508e368f7123a173943cd49c3b32b72d7bdf718 Mon Sep 17 00:00:00 2001 From: buenaflor Date: Mon, 24 Apr 2023 11:43:28 +0200 Subject: [PATCH 2/5] add sample integration test for beforeSend --- .../SentryOptionsConfigurator.kt | 11 +++++ .../extensions/SentryOptionsExtensions.kt | 10 ++-- .../SentryOptionsConfigurator.kt | 25 ++++++++++ .../BeforeSendIntegrationTest.kt | 49 +++++++++++++++++++ .../SentryOptionsConfigurator.kt | 6 +++ 5 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 sentry-kotlin-multiplatform/src/commonAppleTest/kotlin/io/sentry/kotlin/multiplatform/SentryOptionsConfigurator.kt create mode 100644 sentry-kotlin-multiplatform/src/commonJvmTest/kotlin/io/sentry/kotlin/multiplatform/SentryOptionsConfigurator.kt create mode 100644 sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/BeforeSendIntegrationTest.kt create mode 100644 sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/SentryOptionsConfigurator.kt diff --git a/sentry-kotlin-multiplatform/src/commonAppleTest/kotlin/io/sentry/kotlin/multiplatform/SentryOptionsConfigurator.kt b/sentry-kotlin-multiplatform/src/commonAppleTest/kotlin/io/sentry/kotlin/multiplatform/SentryOptionsConfigurator.kt new file mode 100644 index 00000000..53eeb8dd --- /dev/null +++ b/sentry-kotlin-multiplatform/src/commonAppleTest/kotlin/io/sentry/kotlin/multiplatform/SentryOptionsConfigurator.kt @@ -0,0 +1,11 @@ +package io.sentry.kotlin.multiplatform + +actual class SentryOptionsConfigurator { + actual fun applyOptions(optionsConfiguration: OptionsConfiguration): SentryEvent? { + return SentryEvent() + } + + actual fun applyOptions(options: SentryOptions): SentryEvent? { + TODO("Not yet implemented") + } +} diff --git a/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/SentryOptionsExtensions.kt b/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/SentryOptionsExtensions.kt index d3b1906e..f793dda9 100644 --- a/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/SentryOptionsExtensions.kt +++ b/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/extensions/SentryOptionsExtensions.kt @@ -44,8 +44,12 @@ internal fun JvmSentryOptions.applyJvmBaseOptions(options: SentryOptions) { options.beforeBreadcrumb?.invoke(jvmBreadcrumb.toKmpBreadcrumb())?.toJvmBreadcrumb() } setBeforeSend { jvmSentryEvent, hint -> - options.beforeSend?.invoke(SentryEvent(jvmSentryEvent))?.let { - jvmSentryEvent.applyKmpEvent(it) - } ?: jvmSentryEvent + if (options.beforeSend == null) { + jvmSentryEvent + } else { + options.beforeSend?.invoke(SentryEvent(jvmSentryEvent))?.let { + jvmSentryEvent.applyKmpEvent(it) + } + } } } diff --git a/sentry-kotlin-multiplatform/src/commonJvmTest/kotlin/io/sentry/kotlin/multiplatform/SentryOptionsConfigurator.kt b/sentry-kotlin-multiplatform/src/commonJvmTest/kotlin/io/sentry/kotlin/multiplatform/SentryOptionsConfigurator.kt new file mode 100644 index 00000000..d7131a51 --- /dev/null +++ b/sentry-kotlin-multiplatform/src/commonJvmTest/kotlin/io/sentry/kotlin/multiplatform/SentryOptionsConfigurator.kt @@ -0,0 +1,25 @@ +package io.sentry.kotlin.multiplatform + +import io.sentry.Hint +import io.sentry.kotlin.multiplatform.extensions.applyJvmBaseOptions + +actual class SentryOptionsConfigurator { + actual fun applyOptions(optionsConfiguration: OptionsConfiguration): SentryEvent? { + val kmpOptions = SentryOptions() + optionsConfiguration.invoke(kmpOptions) + return applyOptions(kmpOptions) + } + + actual fun applyOptions(options: SentryOptions): SentryEvent? { + val jvmOptions = JvmSentryOptions() + jvmOptions.applyJvmBaseOptions(options) + val jvmSentryEvent = JvmSentryEvent() + val jvmHint = Hint() + val jvmModifiedSentryEvent = jvmOptions.beforeSend?.execute(jvmSentryEvent, jvmHint) + return if (jvmModifiedSentryEvent == null) { + null + } else { + SentryEvent(jvmModifiedSentryEvent) + } + } +} diff --git a/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/BeforeSendIntegrationTest.kt b/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/BeforeSendIntegrationTest.kt new file mode 100644 index 00000000..a4270004 --- /dev/null +++ b/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/BeforeSendIntegrationTest.kt @@ -0,0 +1,49 @@ +package io.sentry.kotlin.multiplatform + +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotNull +import kotlin.test.assertNull + +class BeforeSendIntegrationTest { + private val sentryOptionsConfigurator = SentryOptionsConfigurator() + + @Test + fun `event is not null if KMP beforeSend option is null`() { + val event = sentryOptionsConfigurator.applyOptions() + assertNotNull(event) + } + + @Test + fun `event is null if KMP beforeSend callback config returns null`() { + val event = sentryOptionsConfigurator.applyOptions { + it.beforeSend = { + null + } + } + assertNull(event) + } + + @Test + fun `event is not null if KMP beforeSend callback config returns not null`() { + val event = sentryOptionsConfigurator.applyOptions { + it.beforeSend = { event -> + event + } + } + assertNotNull(event) + } + + @Test + fun `event is modified if KMP beforeSend callback config modifies it`() { + val expected = "test" + val event = sentryOptionsConfigurator.applyOptions { + it.beforeSend = { event -> + event.logger = expected + event + } + } + assertNotNull(event) + assertEquals(expected, event.logger) + } +} diff --git a/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/SentryOptionsConfigurator.kt b/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/SentryOptionsConfigurator.kt new file mode 100644 index 00000000..2634d3ca --- /dev/null +++ b/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/SentryOptionsConfigurator.kt @@ -0,0 +1,6 @@ +package io.sentry.kotlin.multiplatform + +expect class SentryOptionsConfigurator() { + fun applyOptions(optionsConfiguration: OptionsConfiguration): SentryEvent? + fun applyOptions(options: SentryOptions = SentryOptions()): SentryEvent? +} From 103a735a809ed2056ecaa9bc7819154025efb903 Mon Sep 17 00:00:00 2001 From: buenaflor Date: Mon, 24 Apr 2023 12:04:55 +0200 Subject: [PATCH 3/5] add more integration tests --- .../extensions/SentryOptionsExtensions.kt | 15 +- .../multiplatform/SentryEventConfigurator.kt | 25 ++ .../SentryOptionsConfigurator.kt | 11 - ...igurator.kt => SentryEventConfigurator.kt} | 6 +- .../BeforeSendIntegrationTest.kt | 213 +++++++++++++++++- ...igurator.kt => SentryEventConfigurator.kt} | 3 +- 6 files changed, 247 insertions(+), 26 deletions(-) create mode 100644 sentry-kotlin-multiplatform/src/commonAppleTest/kotlin/io/sentry/kotlin/multiplatform/SentryEventConfigurator.kt delete mode 100644 sentry-kotlin-multiplatform/src/commonAppleTest/kotlin/io/sentry/kotlin/multiplatform/SentryOptionsConfigurator.kt rename sentry-kotlin-multiplatform/src/commonJvmTest/kotlin/io/sentry/kotlin/multiplatform/{SentryOptionsConfigurator.kt => SentryEventConfigurator.kt} (83%) rename sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/{SentryOptionsConfigurator.kt => SentryEventConfigurator.kt} (72%) diff --git a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/SentryOptionsExtensions.kt b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/SentryOptionsExtensions.kt index 947a7896..973de837 100644 --- a/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/SentryOptionsExtensions.kt +++ b/sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/SentryOptionsExtensions.kt @@ -51,12 +51,15 @@ internal fun CocoaSentryOptions.applyCocoaBaseOptions(options: SentryOptions) { event?.sdk = sdk - val modifiedEvent = event?.let { SentryEvent(it) }?.let { unwrappedEvent -> - val result = options.beforeSend?.invoke(unwrappedEvent) - result?.let { event.applyKmpEvent(it) } - } ?: event - - dropKotlinCrashEvent(modifiedEvent as NSExceptionSentryEvent?) as CocoaSentryEvent? + if (options.beforeSend == null) { + dropKotlinCrashEvent(event as NSExceptionSentryEvent?) as CocoaSentryEvent? + } else { + val modifiedEvent = event?.let { SentryEvent(it) }?.let { unwrappedEvent -> + val result = options.beforeSend?.invoke(unwrappedEvent) + result?.let { event.applyKmpEvent(it) } + } + dropKotlinCrashEvent(modifiedEvent as NSExceptionSentryEvent?) as CocoaSentryEvent? + } } val sdkName = options.sdk?.name ?: BuildKonfig.SENTRY_KMP_COCOA_SDK_NAME diff --git a/sentry-kotlin-multiplatform/src/commonAppleTest/kotlin/io/sentry/kotlin/multiplatform/SentryEventConfigurator.kt b/sentry-kotlin-multiplatform/src/commonAppleTest/kotlin/io/sentry/kotlin/multiplatform/SentryEventConfigurator.kt new file mode 100644 index 00000000..9577fd61 --- /dev/null +++ b/sentry-kotlin-multiplatform/src/commonAppleTest/kotlin/io/sentry/kotlin/multiplatform/SentryEventConfigurator.kt @@ -0,0 +1,25 @@ +package io.sentry.kotlin.multiplatform + +import io.sentry.kotlin.multiplatform.extensions.applyCocoaBaseOptions + +actual class SentryEventConfigurator { + private val cocoaSentryEvent = CocoaSentryEvent() + actual val originalEvent: SentryEvent = SentryEvent(cocoaSentryEvent) + + actual fun applyOptions(optionsConfiguration: OptionsConfiguration): SentryEvent? { + val kmpOptions = SentryOptions() + optionsConfiguration.invoke(kmpOptions) + return applyOptions(kmpOptions) + } + + actual fun applyOptions(options: SentryOptions): SentryEvent? { + val cocoaOptions = CocoaSentryOptions() + cocoaOptions.applyCocoaBaseOptions(options) + val cocoaModifiedSentryEvent = cocoaOptions.beforeSend?.invoke(cocoaSentryEvent) + return if (cocoaModifiedSentryEvent == null) { + null + } else { + SentryEvent(cocoaModifiedSentryEvent) + } + } +} diff --git a/sentry-kotlin-multiplatform/src/commonAppleTest/kotlin/io/sentry/kotlin/multiplatform/SentryOptionsConfigurator.kt b/sentry-kotlin-multiplatform/src/commonAppleTest/kotlin/io/sentry/kotlin/multiplatform/SentryOptionsConfigurator.kt deleted file mode 100644 index 53eeb8dd..00000000 --- a/sentry-kotlin-multiplatform/src/commonAppleTest/kotlin/io/sentry/kotlin/multiplatform/SentryOptionsConfigurator.kt +++ /dev/null @@ -1,11 +0,0 @@ -package io.sentry.kotlin.multiplatform - -actual class SentryOptionsConfigurator { - actual fun applyOptions(optionsConfiguration: OptionsConfiguration): SentryEvent? { - return SentryEvent() - } - - actual fun applyOptions(options: SentryOptions): SentryEvent? { - TODO("Not yet implemented") - } -} diff --git a/sentry-kotlin-multiplatform/src/commonJvmTest/kotlin/io/sentry/kotlin/multiplatform/SentryOptionsConfigurator.kt b/sentry-kotlin-multiplatform/src/commonJvmTest/kotlin/io/sentry/kotlin/multiplatform/SentryEventConfigurator.kt similarity index 83% rename from sentry-kotlin-multiplatform/src/commonJvmTest/kotlin/io/sentry/kotlin/multiplatform/SentryOptionsConfigurator.kt rename to sentry-kotlin-multiplatform/src/commonJvmTest/kotlin/io/sentry/kotlin/multiplatform/SentryEventConfigurator.kt index d7131a51..2122bc80 100644 --- a/sentry-kotlin-multiplatform/src/commonJvmTest/kotlin/io/sentry/kotlin/multiplatform/SentryOptionsConfigurator.kt +++ b/sentry-kotlin-multiplatform/src/commonJvmTest/kotlin/io/sentry/kotlin/multiplatform/SentryEventConfigurator.kt @@ -3,7 +3,10 @@ package io.sentry.kotlin.multiplatform import io.sentry.Hint import io.sentry.kotlin.multiplatform.extensions.applyJvmBaseOptions -actual class SentryOptionsConfigurator { +actual class SentryEventConfigurator { + private val jvmSentryEvent = JvmSentryEvent() + actual val originalEvent: SentryEvent = SentryEvent(jvmSentryEvent) + actual fun applyOptions(optionsConfiguration: OptionsConfiguration): SentryEvent? { val kmpOptions = SentryOptions() optionsConfiguration.invoke(kmpOptions) @@ -13,7 +16,6 @@ actual class SentryOptionsConfigurator { actual fun applyOptions(options: SentryOptions): SentryEvent? { val jvmOptions = JvmSentryOptions() jvmOptions.applyJvmBaseOptions(options) - val jvmSentryEvent = JvmSentryEvent() val jvmHint = Hint() val jvmModifiedSentryEvent = jvmOptions.beforeSend?.execute(jvmSentryEvent, jvmHint) return if (jvmModifiedSentryEvent == null) { diff --git a/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/BeforeSendIntegrationTest.kt b/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/BeforeSendIntegrationTest.kt index a4270004..b9e71e3d 100644 --- a/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/BeforeSendIntegrationTest.kt +++ b/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/BeforeSendIntegrationTest.kt @@ -1,22 +1,24 @@ package io.sentry.kotlin.multiplatform +import io.sentry.kotlin.multiplatform.protocol.Breadcrumb +import io.sentry.kotlin.multiplatform.protocol.Message import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotNull import kotlin.test.assertNull class BeforeSendIntegrationTest { - private val sentryOptionsConfigurator = SentryOptionsConfigurator() + private val sentryEventConfigurator = SentryEventConfigurator() @Test fun `event is not null if KMP beforeSend option is null`() { - val event = sentryOptionsConfigurator.applyOptions() + val event = sentryEventConfigurator.applyOptions() assertNotNull(event) } @Test fun `event is null if KMP beforeSend callback config returns null`() { - val event = sentryOptionsConfigurator.applyOptions { + val event = sentryEventConfigurator.applyOptions { it.beforeSend = { null } @@ -26,7 +28,7 @@ class BeforeSendIntegrationTest { @Test fun `event is not null if KMP beforeSend callback config returns not null`() { - val event = sentryOptionsConfigurator.applyOptions { + val event = sentryEventConfigurator.applyOptions { it.beforeSend = { event -> event } @@ -35,9 +37,9 @@ class BeforeSendIntegrationTest { } @Test - fun `event is modified if KMP beforeSend callback config modifies it`() { + fun `event logger is modified if KMP beforeSend callback config modifies it`() { val expected = "test" - val event = sentryOptionsConfigurator.applyOptions { + val event = sentryEventConfigurator.applyOptions { it.beforeSend = { event -> event.logger = expected event @@ -46,4 +48,203 @@ class BeforeSendIntegrationTest { assertNotNull(event) assertEquals(expected, event.logger) } + + @Test + fun `event level is modified if KMP beforeSend callback config modifies it`() { + val expected = SentryLevel.DEBUG + val event = sentryEventConfigurator.applyOptions { + it.beforeSend = { event -> + event.level = expected + event + } + } + assertNotNull(event) + assertEquals(expected, event.level) + } + + @Test + fun `event message is modified if KMP beforeSend callback config modifies it`() { + val expected = Message("test") + val event = sentryEventConfigurator.applyOptions { + it.beforeSend = { event -> + event.message = expected + event + } + } + assertNotNull(event) + assertEquals(expected, event.message) + } + + @Test + fun `event release is modified if KMP beforeSend callback config modifies it`() { + val expected = "test" + val event = sentryEventConfigurator.applyOptions { + it.beforeSend = { event -> + event.release = expected + event + } + } + assertNotNull(event) + assertEquals(expected, event.release) + } + + @Test + fun `event environment is modified if KMP beforeSend callback config modifies it`() { + val expected = "test" + val event = sentryEventConfigurator.applyOptions { + it.beforeSend = { event -> + event.environment = expected + event + } + } + assertNotNull(event) + assertEquals(expected, event.environment) + } + + @Test + fun `event serverName is modified if KMP beforeSend callback config modifies it`() { + val expected = "test" + val event = sentryEventConfigurator.applyOptions { + it.beforeSend = { event -> + event.serverName = expected + event + } + } + assertNotNull(event) + assertEquals(expected, event.serverName) + } + + @Test + fun `event dist is modified if KMP beforeSend callback config modifies it`() { + val expected = "test" + val event = sentryEventConfigurator.applyOptions { + it.beforeSend = { event -> + event.dist = expected + event + } + } + assertNotNull(event) + assertEquals(expected, event.dist) + } + + @Test + fun `event fingerprint is modified if KMP beforeSend callback config modifies it`() { + val expected = mutableListOf("test") + val event = sentryEventConfigurator.applyOptions { + it.beforeSend = { event -> + event.fingerprint = expected + event + } + } + assertNotNull(event) + assertEquals(expected, event.fingerprint) + } + + @Test + fun `event tags are modified if KMP beforeSend callback config modifies it`() { + val expected = mutableMapOf("test" to "test") + val event = sentryEventConfigurator.applyOptions { + it.beforeSend = { event -> + event.tags = expected + event + } + } + assertNotNull(event) + assertEquals(expected, event.tags) + } + + @Test + fun `event breadcrumbs are modified if KMP beforeSend callback config modifies it`() { + val expected = mutableListOf(Breadcrumb.debug("test")) + val event = sentryEventConfigurator.applyOptions { + it.beforeSend = { event -> + event.breadcrumbs = expected + event + } + } + assertNotNull(event) + assertEquals(expected.first().type, event.breadcrumbs.first().type) + assertEquals(expected.first().message, event.breadcrumbs.first().message) + assertEquals(expected.first().level, event.breadcrumbs.first().level) + } + + @Test + fun `event logger is not modified if KMP beforeSend callback config is not modified`() { + val originalEvent = sentryEventConfigurator.originalEvent + val event = sentryEventConfigurator.applyOptions() + assertNotNull(event) + assertEquals(originalEvent.logger, event.logger) + } + + @Test + fun `event level is not modified if KMP beforeSend callback config is not modified`() { + val originalEvent = sentryEventConfigurator.originalEvent + val event = sentryEventConfigurator.applyOptions() + assertNotNull(event) + assertEquals(originalEvent.level, event.level) + } + + @Test + fun `event message is not modified if KMP beforeSend callback config is not modified`() { + val originalEvent = sentryEventConfigurator.originalEvent + val event = sentryEventConfigurator.applyOptions() + assertNotNull(event) + assertEquals(originalEvent.message, event.message) + } + + @Test + fun `event release is not modified if KMP beforeSend callback config is not modified`() { + val originalEvent = sentryEventConfigurator.originalEvent + val event = sentryEventConfigurator.applyOptions() + assertNotNull(event) + assertEquals(originalEvent.release, event.release) + } + + @Test + fun `event environment is not modified if KMP beforeSend callback config is not modified`() { + val originalEvent = sentryEventConfigurator.originalEvent + val event = sentryEventConfigurator.applyOptions() + assertNotNull(event) + assertEquals(originalEvent.environment, event.environment) + } + + @Test + fun `event serverName is not modified if KMP beforeSend callback config is not modified`() { + val originalEvent = sentryEventConfigurator.originalEvent + val event = sentryEventConfigurator.applyOptions() + assertNotNull(event) + assertEquals(originalEvent.serverName, event.serverName) + } + + @Test + fun `event dist is not modified if KMP beforeSend callback config is not modified`() { + val originalEvent = sentryEventConfigurator.originalEvent + val event = sentryEventConfigurator.applyOptions() + assertNotNull(event) + assertEquals(originalEvent.dist, event.dist) + } + + @Test + fun `event fingerprint is not modified if KMP beforeSend callback config is not modified`() { + val originalEvent = sentryEventConfigurator.originalEvent + val event = sentryEventConfigurator.applyOptions() + assertNotNull(event) + assertEquals(originalEvent.fingerprint, event.fingerprint) + } + + @Test + fun `event tags are not modified if KMP beforeSend callback config is not modified`() { + val originalEvent = sentryEventConfigurator.originalEvent + val event = sentryEventConfigurator.applyOptions() + assertNotNull(event) + assertEquals(originalEvent.tags, event.tags) + } + + @Test + fun `event breadcrumbs are not modified if KMP beforeSend callback config is not modified`() { + val originalEvent = sentryEventConfigurator.originalEvent + val event = sentryEventConfigurator.applyOptions() + assertNotNull(event) + assertEquals(originalEvent.breadcrumbs, event.breadcrumbs) + } } diff --git a/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/SentryOptionsConfigurator.kt b/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/SentryEventConfigurator.kt similarity index 72% rename from sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/SentryOptionsConfigurator.kt rename to sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/SentryEventConfigurator.kt index 2634d3ca..2dfcf25f 100644 --- a/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/SentryOptionsConfigurator.kt +++ b/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/SentryEventConfigurator.kt @@ -1,6 +1,7 @@ package io.sentry.kotlin.multiplatform -expect class SentryOptionsConfigurator() { +expect class SentryEventConfigurator() { + val originalEvent: SentryEvent fun applyOptions(optionsConfiguration: OptionsConfiguration): SentryEvent? fun applyOptions(options: SentryOptions = SentryOptions()): SentryEvent? } From f1f6609e2970de6749d58e2d3fda6726b65cc637 Mon Sep 17 00:00:00 2001 From: buenaflor Date: Mon, 24 Apr 2023 12:15:12 +0200 Subject: [PATCH 4/5] update docs --- .../io/sentry/kotlin/multiplatform/SentryEventConfigurator.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/SentryEventConfigurator.kt b/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/SentryEventConfigurator.kt index 2dfcf25f..d995661d 100644 --- a/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/SentryEventConfigurator.kt +++ b/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/SentryEventConfigurator.kt @@ -1,5 +1,9 @@ package io.sentry.kotlin.multiplatform +/** + * This class deals with configuring and modifying a SentryEvent. + * It is used to test any code that can alter a SentryEvent. + */ expect class SentryEventConfigurator() { val originalEvent: SentryEvent fun applyOptions(optionsConfiguration: OptionsConfiguration): SentryEvent? From 419edc4f2f037864690735b6c28226224fd433b6 Mon Sep 17 00:00:00 2001 From: buenaflor Date: Mon, 24 Apr 2023 12:34:14 +0200 Subject: [PATCH 5/5] update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b78db735..4b86f54c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Fixes + +- fix: beforeSend dropping events if not set in options ([#79](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/79)) + ## 0.1.0 ### Features