Skip to content

Commit 83187fb

Browse files
authored
fix: initWithPlatforms not sending events if beforeSend is not set on iOS (#366)
* Update * Update SentryBridgeTest.apple.kt * Update CHANGELOG * Update * Update * Podspec
1 parent 90c25c6 commit 83187fb

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
### Fixes
1111

1212
- Do not throw if exec operation fails ([#360](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/360))
13+
- `initWithPlatforms` not sending events if `beforeSend` is not set on iOS ([#366](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/366))
1314

1415
### Miscellaneous
1516

sentry-kotlin-multiplatform/src/appleMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.apple.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ public actual abstract class Context
2020
// like on JVM and Android, we may do that later on if needed.
2121
internal actual fun SentryPlatformOptions.prepareForInit() {
2222
val cocoa = this as? CocoaSentryOptions
23-
val existingBeforeSend = cocoa?.beforeSend
23+
val userDefinedBeforeSend = cocoa?.beforeSend
2424
val modifiedBeforeSend: (CocoaSentryEvent?) -> CocoaSentryEvent? = beforeSend@{ event ->
2525
// Return early if the user's beforeSend returns null
26-
if (existingBeforeSend?.invoke(event) == null) {
26+
if (userDefinedBeforeSend != null && userDefinedBeforeSend.invoke(event) == null) {
2727
return@beforeSend null
2828
}
29-
3029
val cocoaName = BuildKonfig.SENTRY_COCOA_PACKAGE_NAME
3130
val cocoaVersion = BuildKonfig.SENTRY_COCOA_VERSION
3231

sentry-kotlin-multiplatform/src/appleTest/kotlin/io/sentry/kotlin/multiplatform/SentryBridgeTest.apple.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@ actual class SentryBridgeTest {
8989
assert(option.beforeSend!!.invoke(CocoaSentryEvent()) != null)
9090
}
9191

92+
@Test
93+
actual fun `default beforeSend in init does not drop the event after prepareForInit`() {
94+
fixture.sut.init { }
95+
96+
val option = SentryPlatformOptions().apply {
97+
fixture.sentryInstance.lastConfiguration?.invoke(this)
98+
prepareForInit()
99+
}.let { it as CocoaSentryOptions }
100+
101+
assert(option.beforeSend != null)
102+
assert(option.beforeSend!!.invoke(CocoaSentryEvent()) != null)
103+
}
104+
92105
@Test
93106
actual fun `init sets the SDK packages`() {
94107
// GIVEN

sentry-kotlin-multiplatform/src/commonJvmTest/kotlin/io/sentry/kotlin/multiplatform/SentryBridgeTest.commonJvm.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,19 @@ actual class SentryBridgeTest {
7373
assert(option.beforeSend!!.execute(JvmSentryEvent(), Hint()) != null)
7474
}
7575

76+
@Test
77+
actual fun `default beforeSend in init does not drop the event after prepareForInit`() {
78+
fixture.sut.init { }
79+
80+
val option = SentryPlatformOptions().apply {
81+
fixture.sentryInstance.lastConfiguration?.invoke(this)
82+
prepareForInit()
83+
}.let { it as JvmSentryOptions }
84+
85+
assert(option.beforeSend != null)
86+
assert(option.beforeSend!!.execute(JvmSentryEvent(), Hint()) != null)
87+
}
88+
7689
@Test
7790
actual fun `init sets the SDK packages`() {
7891
// WHEN

sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/SentryBridgeTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ expect class SentryBridgeTest {
44
fun `init sets correct configuration`()
55
fun `setting null in beforeSend during init drops the event`()
66
fun `default beforeSend in init does not drop the event`()
7+
fun `default beforeSend in init does not drop the event after prepareForInit`()
78
fun `init sets the SDK packages`()
89
fun `init sets SDK version and name`()
910
}

0 commit comments

Comments
 (0)