Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

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

existingBeforeSend?.invoke(event)
dropKotlinCrashEvent(event)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`()
}
Loading