
OpenTelemetry spec implementation offering both a native implementation and a compatibility façade over the Java SDK, with tracing, logging, and API/noop instrumentation modules.
An implementation of the OpenTelemetry specification as a Kotlin Multiplatform Library.
This API operates in 2 modes:
The following targets are supported:
dependencies {
val otelKotlinVersion = "0.1.0-alpha"
implementation("io.opentelemetry.kotlin:core:$otelKotlinVersion")
implementation("io.opentelemetry.kotlin:implementation:$otelKotlinVersion")
}val otelKotlin = createOpenTelemetry {
// configure SDK here
}Compatibility mode allows you to use a Kotlin API that 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.
dependencies {
val otelKotlinVersion = "0.1.0-alpha"
implementation("io.opentelemetry.kotlin:core:$otelKotlinVersion")
implementation("io.opentelemetry.kotlin:compat:$otelKotlinVersion")
}val otelJava = io.opentelemetry.sdk.OpenTelemetrySdk.builder().build()
val otelKotlin = otelJava.toOtelKotlinApi()
// or alternatively, create an instance that uses opentelemetry-java under the hood
val otelKotlin = createCompatOpenTelemetry {
// configure SDK here
}If you need to instrument code outside the module where the OpenTelemetry SDK initializes, only
the api and noop dependencies are required:
dependencies {
val otelKotlinVersion = "0.1.0-alpha"
implementation("io.opentelemetry.kotlin:api:$otelKotlinVersion")
implementation("io.opentelemetry.kotlin:noop:$otelKotlinVersion")
}This ensures that you are writing instrumentation solely against OpenTelemetry's Instrumentation API
and allows straightforward injection of different OpenTelemetry implementations. This is
particularly useful for library authors who can instrument an SDK with the optional noop module
by default, then ask consumers to pass in a real instance, as demonstrated below:
fun example(otel: OpenTelemetry = NoopOpenTelemetry) {
val logger = otel.loggerProvider.getLogger("my_logger")
logger.log("Hello, World!")
}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!")The API is subject to breaking change without notice and most symbols require an opt-in. You can
opt-in on a case-by-case basis by adding @OptIn(ExperimentalApi::class) at each call site.
Alternatively, you can opt-in for your whole module or project by altering Kotlin's compiler
arguments:
kotlin {
optIn.add("io.opentelemetry.kotlin.ExperimentalApi")
}Example usage of the library can be found here.
Got feedback or found a bug? Please open a GitHub issue and we'll get back to you.
We are currently resource constrained and are actively seeking new contributors interested in working towards approver / maintainer roles. In addition to the documentation for approver / maintainer roles and the contributing guide, here are some additional notes on engaging:
For more information about the maintainer role, see the community repository.
For more information about the approver role, see the community repository.
An implementation of the OpenTelemetry specification as a Kotlin Multiplatform Library.
This API operates in 2 modes:
The following targets are supported:
dependencies {
val otelKotlinVersion = "0.1.0-alpha"
implementation("io.opentelemetry.kotlin:core:$otelKotlinVersion")
implementation("io.opentelemetry.kotlin:implementation:$otelKotlinVersion")
}val otelKotlin = createOpenTelemetry {
// configure SDK here
}Compatibility mode allows you to use a Kotlin API that 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.
dependencies {
val otelKotlinVersion = "0.1.0-alpha"
implementation("io.opentelemetry.kotlin:core:$otelKotlinVersion")
implementation("io.opentelemetry.kotlin:compat:$otelKotlinVersion")
}val otelJava = io.opentelemetry.sdk.OpenTelemetrySdk.builder().build()
val otelKotlin = otelJava.toOtelKotlinApi()
// or alternatively, create an instance that uses opentelemetry-java under the hood
val otelKotlin = createCompatOpenTelemetry {
// configure SDK here
}If you need to instrument code outside the module where the OpenTelemetry SDK initializes, only
the api and noop dependencies are required:
dependencies {
val otelKotlinVersion = "0.1.0-alpha"
implementation("io.opentelemetry.kotlin:api:$otelKotlinVersion")
implementation("io.opentelemetry.kotlin:noop:$otelKotlinVersion")
}This ensures that you are writing instrumentation solely against OpenTelemetry's Instrumentation API
and allows straightforward injection of different OpenTelemetry implementations. This is
particularly useful for library authors who can instrument an SDK with the optional noop module
by default, then ask consumers to pass in a real instance, as demonstrated below:
fun example(otel: OpenTelemetry = NoopOpenTelemetry) {
val logger = otel.loggerProvider.getLogger("my_logger")
logger.log("Hello, World!")
}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!")The API is subject to breaking change without notice and most symbols require an opt-in. You can
opt-in on a case-by-case basis by adding @OptIn(ExperimentalApi::class) at each call site.
Alternatively, you can opt-in for your whole module or project by altering Kotlin's compiler
arguments:
kotlin {
optIn.add("io.opentelemetry.kotlin.ExperimentalApi")
}Example usage of the library can be found here.
Got feedback or found a bug? Please open a GitHub issue and we'll get back to you.
We are currently resource constrained and are actively seeking new contributors interested in working towards approver / maintainer roles. In addition to the documentation for approver / maintainer roles and the contributing guide, here are some additional notes on engaging:
For more information about the maintainer role, see the community repository.
For more information about the approver role, see the community repository.