Skip to content

Commit 2b0f3a8

Browse files
committed
Update
1 parent 3500fab commit 2b0f3a8

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal actual fun SentryPlatformOptions.prepareForInit() {
2323
val existingBeforeSend = 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 (existingBeforeSend != null && existingBeforeSend.invoke(event) == null) {
2727
return@beforeSend null
2828
}
2929

@@ -37,6 +37,7 @@ internal actual fun SentryPlatformOptions.prepareForInit() {
3737
sdk["packages"] = packages
3838
event?.sdk = sdk
3939

40+
existingBeforeSend?.invoke(event)
4041
dropKotlinCrashEvent(event)
4142
}
4243

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,25 @@ actual class SentryBridgeTest {
8484
fixture.sentryInstance.lastConfiguration?.invoke(this)
8585
}.let { it as CocoaSentryOptions }
8686

87+
8788
// THEN
8889
assert(option.beforeSend != null)
8990
assert(option.beforeSend!!.invoke(CocoaSentryEvent()) != null)
9091
}
9192

93+
@Test
94+
actual fun `default beforeSend in init does not drop the event after prepareForInit`() {
95+
fixture.sut.init { }
96+
97+
val option = SentryPlatformOptions().apply {
98+
fixture.sentryInstance.lastConfiguration?.invoke(this)
99+
prepareForInit()
100+
}.let { it as CocoaSentryOptions }
101+
102+
assert(option.beforeSend != null)
103+
assert(option.beforeSend!!.invoke(CocoaSentryEvent()) != null)
104+
}
105+
92106
@Test
93107
actual fun `init sets the SDK packages`() {
94108
// 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)