Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add Sentry.isEnabled() to common code #273

Merged
merged 7 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Features

- Add `Sentry.isEnabled()` to common code ([#273](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/273))

## 0.9.0

### Improvements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ internal expect class SentryBridge(sentryInstance: SentryInstance = SentryPlatfo

fun isCrashedLastRun(): Boolean

fun isEnabled(): Boolean

fun close()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import kotlinx.coroutines.test.runTest
import kotlin.test.AfterTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
Expand Down Expand Up @@ -225,6 +226,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"
Expand Down