An implementation of the OpenTelemetry specification as a Kotlin Multiplatform Library, developed by embrace.io.
This API operates in 2 modes:
- Compatibility mode, where it acts as a façade for the OpenTelemetry Java SDK
- Regular mode, where it captures telemetry via a Kotlin Multiplatform (KMP) implementation
The following targets are supported:
- Android (API >=21)
- JVM (JDK >= 8)
Other targets compile but are not considered sufficiently tested to count as 'supported' at this current time.
- Tracing
- Logging
- Add the following dependencies to your Android/Java project:
dependencies {
implementation("io.embrace.opentelemetry.kotlin:opentelemetry-kotlin:<latest-version>")
implementation("io.embrace.opentelemetry.kotlin:opentelemetry-kotlin-implementation:<latest-version>")
}
- Initialize the SDK:
val otelKotlin = createOpenTelemetryKotlin()
- Use the Kotlin API in your app
Compatibility mode allows you to use a Kotlin API that under the hood uses the OpenTelemetry Java SDK under the hood to export telemetry. This can be helpful if you already use the Java implementation, or don't want to use the Kotlin implementation for whatever reason.
- Add the following dependencies to your Android/Java project:
dependencies {
implementation("io.embrace.opentelemetry.kotlin:opentelemetry-kotlin:<latest-version>")
implementation("io.embrace.opentelemetry.kotlin:opentelemetry-kotlin-compat:<latest-version>")
}
- Wrap your existing OTel Java instance:
val otelJava = io.opentelemetry.sdk.OpenTelemetrySdk.builder().build()
val otelKotlin = otelJava.toOtelKotlinApi()
- Use the Kotlin API instead of the Java API in your app
val tracer = otelKotlin.tracerProvider.getTracer(
name = "kotlin-example-app",
version = "0.1.0"
)
tracer.createSpan("my_span")
val logger = otelKotlin.loggerProvider.getLogger("my_logger")
logger.log("Hello, World!")
Example usage of the library can be found here.
Got feedback or found a bug? Please open a GitHub issue or contact [email protected] and we'll get back to you.
Every day, a snapshot version is published to the maven snapshots repository. You can check the current snapshot version in gradle.properties. To use a snapshot version in your app, you need to add the Central Portal snapshot repository, like this:
repositories {
...
maven {
name = "Central Portal Snapshots"
url = uri("https://central.sonatype.com/repository/maven-snapshots/")
content {
includeGroup("io.embrace.opentelemetry.kotlin")
}
}
...
}