Configure the OpenTelemetry-based telemetry provider
The SDK for Kotlin provides an implementation of the TelemetryProvider interface backed by OpenTelemetry.
Prerequisites
Update your project dependencies to add the OpenTelemetry provider as shown in the following Gradle snippet. Replace X.Y.Z with the version you’re using in your app or with the latest version available (smithy-kotlin
dependencies { implementation(platform("aws.smithy.kotlin:bom:X.Y.Z")) implementation(platform("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom:X.Y.Z")) implementation("aws.smithy.kotlin:telemetry-provider-otel") // OPTIONAL: If you use log4j, the following entry enables the ability to export logs through OTel. runtimeOnly("io.opentelemetry.instrumentation:opentelemetry-log4j-appender-2.17") }
Configure the SDK
The following code configures a service client by using the OpenTelemetry telemetry provider.
import aws.sdk.kotlin.services.s3.S3Client import aws.smithy.kotlin.runtime.telemetry.otel.OpenTelemetryProvider import io.opentelemetry.api.GlobalOpenTelemetry import kotlinx.coroutines.runBlocking fun main() = runBlocking { val otelProvider = OpenTelemetryProvider(GlobalOpenTelemetry.get()) S3Client.fromEnvironment().use { s3 -> telemetryProvider = otelProvider … } }
Note
A discussion of how to configure the OpenTelemetry SDK is outside of the scope of this guide. The OpenTelemetry Java documentation
Resources
The following resources are available to help you get started with OpenTelemetry.
-
Amazon Distro for OpenTelemetry
- Amazon OTeL Distro homepage -
aws-otel-java-instrumentation
- Amazon Distro for OpenTelemetry Java Instrumentation Library -
aws-otel-lambda
- Amazon managed OpenTelemetry Lambda layers -
aws-otel-collector
- Amazon Distro for OpenTelemetry Collector -
Amazon Observability Best Practices
- General best practices for observability specific to Amazon