Sentry Setup for Kotlin Multiplatform

Dependency
Available on Maven Central:
implementation("ch.ubique.kmp:sentry:1.0.0")
You may find the current version and version history in the Releases list.
Features
- Auto-installation is off.
- Disables performance tracing and session tracking.
- Anonymizes user and device.
- Disables all breadcrumbs except for the most recently viewed Screen.
- Adds build metadata to crash reports.
Usage
🤖 Android
Call initUbiqueSentry() in your Application class' onCreate(), or UbiqueSentry.init() if elsewhere.
class ExampleApplication : Application() {
override fun onCreate() {
initUbiqueSentry(
isProduction = BuildConfig.IS_FLAVOR_PROD,
environment = when {
BuildConfig.DEBUG -> "debug"
else -> BuildConfig.FLAVOR
},
buildTimestamp = BuildConfig.BUILD_TIMESTAMP,
buildNumber = BuildConfig.BUILD_NUMBER,
vcsBranch = BuildConfig.BRANCH,
alpakaBuildId = BuildConfig.BUILD_ID,
)
}
}
Parameters
Compose Navigation breadcrumbs
To log Compose Navigation breadcrumbs,
call withSentryObservableEffect()
on your NavHostControllers:
val navController = rememberNavController().withSentryObservableEffect(
enableNavigationBreadcrumbs = true,
enableNavigationTracing = false,
)
🍎 iOS
Call initialize() early in your app's lifecycle (e.g. in your AppDelegate):
import UbiqueSentry
UbiqueSentryKt.initialize(
isProduction: true,
environment: "prod",
buildTimestamp: 1698765432000,
vcsBranch: "develop",
dsn: "https://123abc@sentry/42",
)
Parameters
🌟 Multiplatform
Enable at runtime
To enable or disable Sentry at runtime, set UbiqueSentry.isEnabled at your will.
Non-fatal exceptions
Use UbiqueSentry.captureException() to record non-fatal exceptions.
Messages
Use UbiqueSentry.captureMessage() to send a message as a non-fatal exception to Sentry:
The message is wrapped in a NonFatalException internally and supports the same optional level, extras,
and scopeCallback parameters as captureException().
Breadcrumbs
Use UbiqueSentry.addBreadcrumb() to add a breadcrumb to the current Sentry scope.
The breadcrumb parameter accepts a Breadcrumb instance (e.g. created via Breadcrumb.ui(), Breadcrumb.navigation(), etc.),
and the optional data parameter allows attaching additional key-value pairs to the breadcrumb.
Test Crash
Use UbiqueSentry.crash() to trigger a test crash by throwing an Exception.
Development & Testing
Most features of this library can be implemented with test-driven development using unit tests with a mock webserver instance.
To test any changes locally in an app, you can either include the library via dependency substitution in an application project,
or deploy a build to your local maven repository and include that from any application:
-
Define a unique custom version by setting the VERSION_NAME variable in the file.
Deployment
Create a Release,
setting the Tag to the desired version prefixed with a v.
Each release on GitHub will be deployed to Maven Central.
- Group:
ch.ubique.kmp
- Artifact:
sentry
- Version:
major.minor.revision