# Kotlin on the JVM [Languages](README.md) · [Java](java.md) · [Shared configuration](../../common.md) Use the OpenTelemetry Java SDK for Kotlin backend services on the JVM. This guide uses Java SDK **1.66.0**, whose traces, metrics, and logs are Stable. The separate Kotlin Multiplatform SDK lists all three signals as Development as of 2026-09-28; this JVM example does not establish support for Kotlin/Native, Kotlin/JS, or Android lifecycle behavior. ## Install the dependencies You need JDK 17 or later, Maven, and an installed Kotlin/JVM compiler (`kotlinc`). Create a new directory and save this `pom.xml` to retrieve the Java dependencies: ```xml 4.0.0 examplecorridora-kotlin1 io.opentelemetry opentelemetry-sdk-extension-autoconfigure 1.66.0 io.opentelemetry opentelemetry-exporter-otlp 1.66.0 ``` For an existing Gradle Kotlin/JVM application, the equivalent dependencies are `implementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:1.66.0")` and `implementation("io.opentelemetry:opentelemetry-exporter-otlp:1.66.0")` from Maven Central. Keep your project's Kotlin and JVM toolchain settings. ## Configure and emit Start the [local Collector](../../../collector.md), then configure the SDK: ```sh mvn dependency:copy-dependencies -DoutputDirectory=lib export OTEL_SERVICE_NAME='corridora-kotlin' export OTEL_RESOURCE_ATTRIBUTES='service.version=example-1,deployment.environment.name=development' export OTEL_TRACES_EXPORTER='otlp' export OTEL_METRICS_EXPORTER='none' export OTEL_LOGS_EXPORTER='none' export OTEL_EXPORTER_OTLP_PROTOCOL='http/protobuf' export OTEL_EXPORTER_OTLP_ENDPOINT='http://127.0.0.1:4318' unset OTEL_EXPORTER_OTLP_TRACES_ENDPOINT unset OTEL_EXPORTER_OTLP_HEADERS OTEL_EXPORTER_OTLP_TRACES_HEADERS ``` Save as `Example.kt`: ```kotlin import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk fun main() { val sdk = AutoConfiguredOpenTelemetrySdk.initialize().openTelemetrySdk try { val tracer = sdk.getTracer("corridora.examples.kotlin") val span = tracer.spanBuilder("example.calculate").startSpan() try { span.makeCurrent().use { span.setAttribute("example.language", "kotlin") Thread.sleep(50) println("trace_id=${span.spanContext.traceId}") } } finally { span.end() } } finally { sdk.close() } } ``` Compile and run in a Unix-like shell: ```sh classpath="$(printf '%s:' lib/*.jar)" kotlinc -classpath "$classpath" Example.kt -include-runtime -d example.jar java -cp "example.jar:$classpath" ExampleKt ``` The SDK autoconfiguration module reads the environment. A Kotlin application that builds exporters directly must set the equivalent Java builder options itself. This sample is synchronous so that its context lifetime is explicit. ## Frameworks, coroutines, and correlation The Java agent can instrument supported JVM frameworks used from Kotlin. Agent installation and framework compatibility follow the Java agent's support matrix, not the language extension of the application source. When the agent owns initialization, obtain tracers from `GlobalOpenTelemetry`; do not also construct a second SDK using this sample. For manual coroutine instrumentation, `makeCurrent()` alone is insufficient across arbitrary suspensions and thread changes. Use the compatible `io.opentelemetry:opentelemetry-extension-kotlin` context integration and its `Context.asContextElement()` with the coroutine context. Attach the appropriate parent context to launched work and end spans after that work completes. A `Scope` must not be left active on one thread while a coroutine resumes on another. Supported HTTP clients and server integrations propagate W3C trace context. Custom messaging must carry context through message headers. Use a supported Logback or Log4j bridge/appender to export logs with the current span's IDs; `println` remains standard output. ## Additional signals, direct export, and verification Metrics use the Java meter API and metric exporter. Logs use the Java logs SDK and an application logging bridge. Enable their exporters only after adding the emitting/bridging code; the `none` settings above limit this example to traces. Keep service resources consistent across providers. Keep one SDK for each process, stop new work before shutdown, and allow queued spans to flush. For direct Corridora export, use the HTTPS base endpoint and `OTEL_EXPORTER_OTLP_HEADERS="X-CORRIDORA-KEY=${CORRIDORA_INGEST_KEY}"` from [shared configuration](../../common.md). Autoconfiguration applies these variables; a trace-specific endpoint overrides the base and includes `/v1/traces`. In Corridora, find `corridora-kotlin`, the printed trace ID, and `example.calculate`. If spans split into unrelated traces only under coroutine concurrency, inspect context attachment before changing the exporter. Follow [verification](../../verification.md) for transport and visibility checks.