diff --git a/CHANGELOG.md b/CHANGELOG.md index 66c33267..da39ae9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### Fixes - Do not throw if exec operation fails ([#360](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/360)) +- `initWithPlatforms` not sending events if `beforeSend` is not set on iOS ([#366](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/366)) ### Miscellaneous diff --git a/sentry-kotlin-multiplatform/src/appleMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.apple.kt b/sentry-kotlin-multiplatform/src/appleMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.apple.kt index a954e90b..933ddae0 100644 --- a/sentry-kotlin-multiplatform/src/appleMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.apple.kt +++ b/sentry-kotlin-multiplatform/src/appleMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.apple.kt @@ -20,13 +20,12 @@ public actual abstract class Context // like on JVM and Android, we may do that later on if needed. internal actual fun SentryPlatformOptions.prepareForInit() { val cocoa = this as? CocoaSentryOptions - val existingBeforeSend = cocoa?.beforeSend + val userDefinedBeforeSend = cocoa?.beforeSend val modifiedBeforeSend: (CocoaSentryEvent?) -> CocoaSentryEvent? = beforeSend@{ event -> // Return early if the user's beforeSend returns null - if (existingBeforeSend?.invoke(event) == null) { + if (userDefinedBeforeSend != null && userDefinedBeforeSend.invoke(event) == null) { return@beforeSend null } - val cocoaName = BuildKonfig.SENTRY_COCOA_PACKAGE_NAME val cocoaVersion = BuildKonfig.SENTRY_COCOA_VERSION diff --git a/sentry-kotlin-multiplatform/src/appleTest/kotlin/io/sentry/kotlin/multiplatform/SentryBridgeTest.apple.kt b/sentry-kotlin-multiplatform/src/appleTest/kotlin/io/sentry/kotlin/multiplatform/SentryBridgeTest.apple.kt index 104e39dc..c6b2ebff 100644 --- a/sentry-kotlin-multiplatform/src/appleTest/kotlin/io/sentry/kotlin/multiplatform/SentryBridgeTest.apple.kt +++ b/sentry-kotlin-multiplatform/src/appleTest/kotlin/io/sentry/kotlin/multiplatform/SentryBridgeTest.apple.kt @@ -89,6 +89,19 @@ actual class SentryBridgeTest { assert(option.beforeSend!!.invoke(CocoaSentryEvent()) != null) } + @Test + actual fun `default beforeSend in init does not drop the event after prepareForInit`() { + fixture.sut.init { } + + val option = SentryPlatformOptions().apply { + fixture.sentryInstance.lastConfiguration?.invoke(this) + prepareForInit() + }.let { it as CocoaSentryOptions } + + assert(option.beforeSend != null) + assert(option.beforeSend!!.invoke(CocoaSentryEvent()) != null) + } + @Test actual fun `init sets the SDK packages`() { // GIVEN diff --git a/sentry-kotlin-multiplatform/src/commonJvmTest/kotlin/io/sentry/kotlin/multiplatform/SentryBridgeTest.commonJvm.kt b/sentry-kotlin-multiplatform/src/commonJvmTest/kotlin/io/sentry/kotlin/multiplatform/SentryBridgeTest.commonJvm.kt index da16380e..0d08dbbf 100644 --- a/sentry-kotlin-multiplatform/src/commonJvmTest/kotlin/io/sentry/kotlin/multiplatform/SentryBridgeTest.commonJvm.kt +++ b/sentry-kotlin-multiplatform/src/commonJvmTest/kotlin/io/sentry/kotlin/multiplatform/SentryBridgeTest.commonJvm.kt @@ -73,6 +73,19 @@ actual class SentryBridgeTest { assert(option.beforeSend!!.execute(JvmSentryEvent(), Hint()) != null) } + @Test + actual fun `default beforeSend in init does not drop the event after prepareForInit`() { + fixture.sut.init { } + + val option = SentryPlatformOptions().apply { + fixture.sentryInstance.lastConfiguration?.invoke(this) + prepareForInit() + }.let { it as JvmSentryOptions } + + assert(option.beforeSend != null) + assert(option.beforeSend!!.execute(JvmSentryEvent(), Hint()) != null) + } + @Test actual fun `init sets the SDK packages`() { // WHEN diff --git a/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/SentryBridgeTest.kt b/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/SentryBridgeTest.kt index 76514aca..d44a8d2d 100644 --- a/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/SentryBridgeTest.kt +++ b/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/SentryBridgeTest.kt @@ -4,6 +4,7 @@ expect class SentryBridgeTest { fun `init sets correct configuration`() fun `setting null in beforeSend during init drops the event`() fun `default beforeSend in init does not drop the event`() + fun `default beforeSend in init does not drop the event after prepareForInit`() fun `init sets the SDK packages`() fun `init sets SDK version and name`() }