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.
val otelVersion = "1.31.0-alpha" val smithyKotlinVersion = "0.28.2" dependencies { implementation("aws.smithy.kotlin:telemetry-provider-otel:$smithyKotlinVersion") // 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:$otelVersion") }
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.
-
AWS Distro for OpenTelemetry
- AWS OTeL Distro homepage -
aws-otel-java-instrumentation
- AWS Distro for OpenTelemetry Java Instrumentation Library -
aws-otel-lambda
- AWS managed OpenTelemetry Lambda layers -
aws-otel-collector
- AWS Distro for OpenTelemetry Collector -
AWS Observability Best Practices
- General best practices for observability specific to AWS