Configure the OpenTelemetry-based telemetry provider - AWS SDK for Kotlin

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 contains configuration information on the various approaches: manually, automatically through the Java agent, or the (optional) collector.

Resources

The following resources are available to help you get started with OpenTelemetry.