Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
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