Skip to content

Commit 27c2e03

Browse files
Add Sentry.isEnabled() to common code (#273)
* add function * fix imports * update changelog * Format code * update * update api --------- Co-authored-by: Sentry Github Bot <[email protected]>
1 parent 7715854 commit 27c2e03

File tree

8 files changed

+40
-0
lines changed

8 files changed

+40
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Features
6+
7+
- Add `Sentry.isEnabled()` API to common code ([#273](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/273))
8+
39
## 0.9.0
410

511
### Improvements

sentry-kotlin-multiplatform/api/android/sentry-kotlin-multiplatform.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public final class io/sentry/kotlin/multiplatform/Sentry {
8686
public final fun init (Lkotlin/jvm/functions/Function1;)V
8787
public final fun initWithPlatformOptions (Lkotlin/jvm/functions/Function1;)V
8888
public final fun isCrashedLastRun ()Z
89+
public final fun isEnabled ()Z
8990
public final fun setUser (Lio/sentry/kotlin/multiplatform/protocol/User;)V
9091
}
9192

sentry-kotlin-multiplatform/api/jvm/sentry-kotlin-multiplatform.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public final class io/sentry/kotlin/multiplatform/Sentry {
8383
public final fun init (Lkotlin/jvm/functions/Function1;)V
8484
public final fun initWithPlatformOptions (Lkotlin/jvm/functions/Function1;)V
8585
public final fun isCrashedLastRun ()Z
86+
public final fun isEnabled ()Z
8687
public final fun setUser (Lio/sentry/kotlin/multiplatform/protocol/User;)V
8788
}
8889

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ internal actual class SentryBridge actual constructor(private val sentryInstance
108108
return SentrySDK.crashedLastRun()
109109
}
110110

111+
actual fun isEnabled(): Boolean {
112+
return SentrySDK.isEnabled()
113+
}
114+
111115
actual fun close() {
112116
SentrySDK.close()
113117
}

sentry-kotlin-multiplatform/src/commonJvmMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.commonJvm.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ internal actual class SentryBridge actual constructor(private val sentryInstance
7171
return Sentry.isCrashedLastRun() ?: false
7272
}
7373

74+
actual fun isEnabled(): Boolean {
75+
return Sentry.isEnabled()
76+
}
77+
7478
actual fun close() {
7579
Sentry.close()
7680
}

sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@ internal expect class SentryBridge(sentryInstance: SentryInstance = SentryPlatfo
3030

3131
fun isCrashedLastRun(): Boolean
3232

33+
fun isEnabled(): Boolean
34+
3335
fun close()
3436
}

sentry-kotlin-multiplatform/src/commonMain/kotlin/io/sentry/kotlin/multiplatform/SentryKMP.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ public object Sentry {
154154
throw RuntimeException("Uncaught Exception from Kotlin Multiplatform.")
155155
}
156156

157+
/**
158+
* Checks if the SDK is enabled.
159+
*/
160+
public fun isEnabled(): Boolean {
161+
return bridge.isEnabled()
162+
}
163+
157164
/**
158165
* Closes the SDK.
159166
*/

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import kotlinx.coroutines.test.runTest
77
import kotlin.test.AfterTest
88
import kotlin.test.Test
99
import kotlin.test.assertEquals
10+
import kotlin.test.assertFalse
1011
import kotlin.test.assertNotEquals
1112
import kotlin.test.assertNotNull
1213
import kotlin.test.assertTrue
@@ -225,6 +226,20 @@ class SentryIntegrationTest : BaseSentryTest() {
225226
assertEquals(expectedUsername, actualUsername)
226227
}
227228

229+
@Test
230+
fun `isEnabled returns true when SDK is enabled`() {
231+
sentryInit {
232+
it.dsn = fakeDsn
233+
}
234+
235+
assertTrue(Sentry.isEnabled())
236+
}
237+
238+
@Test
239+
fun `isEnabled returns false when SDK is disabled`() {
240+
assertFalse(Sentry.isEnabled())
241+
}
242+
228243
@Test
229244
fun `global scope sets context correctly with different data types`() = runTest {
230245
val stringKey = "stringKey"

0 commit comments

Comments
 (0)