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 cad8180d..a954e90b 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 @@ -108,6 +108,10 @@ internal actual class SentryBridge actual constructor(private val sentryInstance return SentrySDK.crashedLastRun() } + actual fun isEnabled(): Boolean { + return SentrySDK.isEnabled() + } + actual fun close() { SentrySDK.close() } diff --git a/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.commonJvm.kt b/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.commonJvm.kt index 66443f27..4ddb8d4b 100644 --- a/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.commonJvm.kt +++ b/sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.commonJvm.kt @@ -71,6 +71,10 @@ internal actual class SentryBridge actual constructor(private val sentryInstance return Sentry.isCrashedLastRun() ?: false } + actual fun isEnabled(): Boolean { + return Sentry.isEnabled() + } + actual fun close() { Sentry.close() } diff --git a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.kt b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.kt index 8b517677..167c51ad 100644 --- a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.kt +++ b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.kt @@ -30,5 +30,7 @@ internal expect class SentryBridge(sentryInstance: SentryInstance = SentryPlatfo fun isCrashedLastRun(): Boolean + fun isEnabled(): Boolean + fun close() } diff --git a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/SentryKMP.kt b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/SentryKMP.kt index 6d9b2f3e..9535a38c 100644 --- a/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/SentryKMP.kt +++ b/sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/SentryKMP.kt @@ -154,6 +154,13 @@ public object Sentry { throw RuntimeException("Uncaught Exception from Kotlin Multiplatform.") } + /** + * Checks if the SDK is enabled. + */ + public fun isEnabled(): Boolean { + return bridge.isEnabled() + } + /** * Closes the SDK. */ diff --git a/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/SentryIntegrationTest.kt b/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/SentryIntegrationTest.kt index 9cb7a8b0..4fcc8980 100644 --- a/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/SentryIntegrationTest.kt +++ b/sentry-kotlin-multiplatform/src/commonTest/kotlin/io/sentry/kotlin/multiplatform/SentryIntegrationTest.kt @@ -4,12 +4,7 @@ import io.sentry.kotlin.multiplatform.protocol.Breadcrumb import io.sentry.kotlin.multiplatform.protocol.User import io.sentry.kotlin.multiplatform.utils.fakeDsn import kotlinx.coroutines.test.runTest -import kotlin.test.AfterTest -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertNotEquals -import kotlin.test.assertNotNull -import kotlin.test.assertTrue +import kotlin.test.* class SentryIntegrationTest : BaseSentryTest() { @AfterTest @@ -225,6 +220,20 @@ class SentryIntegrationTest : BaseSentryTest() { assertEquals(expectedUsername, actualUsername) } + @Test + fun `isEnabled returns true when SDK is enabled`() { + sentryInit { + it.dsn = fakeDsn + } + + assertTrue(Sentry.isEnabled()) + } + + @Test + fun `isEnabled returns false when SDK is disabled`() { + assertFalse(Sentry.isEnabled()) + } + @Test fun `global scope sets context correctly with different data types`() = runTest { val stringKey = "stringKey"