From 2b0f3a80f2f7c00f8aefef4158d6930899324156 Mon Sep 17 00:00:00 2001 From: Giancarlo Buenaflor Date: Fri, 4 Apr 2025 03:11:05 +0200 Subject: [PATCH 1/6] Update --- .../kotlin/multiplatform/SentryBridge.apple.kt | 3 ++- .../kotlin/multiplatform/SentryBridgeTest.apple.kt | 14 ++++++++++++++ .../multiplatform/SentryBridgeTest.commonJvm.kt | 13 +++++++++++++ .../kotlin/multiplatform/SentryBridgeTest.kt | 1 + 4 files changed, 30 insertions(+), 1 deletion(-) 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..0570a20a 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 @@ -23,7 +23,7 @@ internal actual fun SentryPlatformOptions.prepareForInit() { val existingBeforeSend = cocoa?.beforeSend val modifiedBeforeSend: (CocoaSentryEvent?) -> CocoaSentryEvent? = beforeSend@{ event -> // Return early if the user's beforeSend returns null - if (existingBeforeSend?.invoke(event) == null) { + if (existingBeforeSend != null && existingBeforeSend.invoke(event) == null) { return@beforeSend null } @@ -37,6 +37,7 @@ internal actual fun SentryPlatformOptions.prepareForInit() { sdk["packages"] = packages event?.sdk = sdk + existingBeforeSend?.invoke(event) dropKotlinCrashEvent(event) } 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..1ccd3087 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 @@ -84,11 +84,25 @@ actual class SentryBridgeTest { fixture.sentryInstance.lastConfiguration?.invoke(this) }.let { it as CocoaSentryOptions } + // THEN assert(option.beforeSend != null) 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`() } From 36ab625a090828404a52c0e088b14f14d7e5c935 Mon Sep 17 00:00:00 2001 From: Giancarlo Buenaflor Date: Wed, 16 Apr 2025 16:52:39 +0200 Subject: [PATCH 2/6] Update SentryBridgeTest.apple.kt --- .../io/sentry/kotlin/multiplatform/SentryBridgeTest.apple.kt | 1 - 1 file changed, 1 deletion(-) 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 1ccd3087..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 @@ -84,7 +84,6 @@ actual class SentryBridgeTest { fixture.sentryInstance.lastConfiguration?.invoke(this) }.let { it as CocoaSentryOptions } - // THEN assert(option.beforeSend != null) assert(option.beforeSend!!.invoke(CocoaSentryEvent()) != null) From 37405f6ea64fc8a6618e32ad5865dee6c3a9343c Mon Sep 17 00:00:00 2001 From: Giancarlo Buenaflor Date: Thu, 17 Apr 2025 00:22:04 +0200 Subject: [PATCH 3/6] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00653181..25eb418f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,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 From 4cb4c02bca6bc39234da8248bc5583d6e705290d Mon Sep 17 00:00:00 2001 From: Giancarlo Buenaflor Date: Thu, 17 Apr 2025 01:25:47 +0200 Subject: [PATCH 4/6] Update --- .../io/sentry/kotlin/multiplatform/SentryBridge.apple.kt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) 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 0570a20a..ab28c06c 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 @@ -22,11 +22,6 @@ internal actual fun SentryPlatformOptions.prepareForInit() { val cocoa = this as? CocoaSentryOptions val existingBeforeSend = cocoa?.beforeSend val modifiedBeforeSend: (CocoaSentryEvent?) -> CocoaSentryEvent? = beforeSend@{ event -> - // Return early if the user's beforeSend returns null - if (existingBeforeSend != null && existingBeforeSend.invoke(event) == null) { - return@beforeSend null - } - val cocoaName = BuildKonfig.SENTRY_COCOA_PACKAGE_NAME val cocoaVersion = BuildKonfig.SENTRY_COCOA_VERSION @@ -37,7 +32,9 @@ internal actual fun SentryPlatformOptions.prepareForInit() { sdk["packages"] = packages event?.sdk = sdk - existingBeforeSend?.invoke(event) + if (existingBeforeSend?.invoke(event) == null) { + return@beforeSend null + } dropKotlinCrashEvent(event) } From cd56975d18146bfafa267e292d11925124211329 Mon Sep 17 00:00:00 2001 From: Giancarlo Buenaflor Date: Thu, 17 Apr 2025 02:13:19 +0200 Subject: [PATCH 5/6] Update --- .../sentry_kotlin_multiplatform.podspec | 2 +- .../io/sentry/kotlin/multiplatform/SentryBridge.apple.kt | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sentry-kotlin-multiplatform/sentry_kotlin_multiplatform.podspec b/sentry-kotlin-multiplatform/sentry_kotlin_multiplatform.podspec index a8d74eec..5ad3341d 100644 --- a/sentry-kotlin-multiplatform/sentry_kotlin_multiplatform.podspec +++ b/sentry-kotlin-multiplatform/sentry_kotlin_multiplatform.podspec @@ -54,4 +54,4 @@ Pod::Spec.new do |spec| } ] -end +end \ No newline at end of file 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 ab28c06c..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,8 +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 (userDefinedBeforeSend != null && userDefinedBeforeSend.invoke(event) == null) { + return@beforeSend null + } val cocoaName = BuildKonfig.SENTRY_COCOA_PACKAGE_NAME val cocoaVersion = BuildKonfig.SENTRY_COCOA_VERSION @@ -32,9 +36,6 @@ internal actual fun SentryPlatformOptions.prepareForInit() { sdk["packages"] = packages event?.sdk = sdk - if (existingBeforeSend?.invoke(event) == null) { - return@beforeSend null - } dropKotlinCrashEvent(event) } From 0a229ed0c9444725a541ceb637407549d550ce33 Mon Sep 17 00:00:00 2001 From: Giancarlo Buenaflor Date: Thu, 17 Apr 2025 02:15:25 +0200 Subject: [PATCH 6/6] Podspec --- sentry-kotlin-multiplatform/sentry_kotlin_multiplatform.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry-kotlin-multiplatform/sentry_kotlin_multiplatform.podspec b/sentry-kotlin-multiplatform/sentry_kotlin_multiplatform.podspec index 5ad3341d..a8d74eec 100644 --- a/sentry-kotlin-multiplatform/sentry_kotlin_multiplatform.podspec +++ b/sentry-kotlin-multiplatform/sentry_kotlin_multiplatform.podspec @@ -54,4 +54,4 @@ Pod::Spec.new do |spec| } ] -end \ No newline at end of file +end