opentelemetry-java-instrume.../instrumentation/ktor/ktor-2.0/library
renovate[bot] c22bb598e5
fix(deps): update spotless packages to v7 (major) (#13004)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Lauri Tulmin <ltulmin@splunk.com>
2025-01-08 07:37:47 -08:00
..
src fix(deps): update spotless packages to v7 (major) (#13004) 2025-01-08 07:37:47 -08:00
README.md Rename ktor tracing to ktor telemetry (#12855) 2024-12-16 19:50:28 -08:00
build.gradle.kts Document (and remove some) upper version test limits (#12945) 2024-12-27 08:54:10 -08:00

README.md

Library Instrumentation for Ktor version 2.x

This package contains libraries to help instrument Ktor. Server and client instrumentations are supported.

Quickstart

Add these dependencies to your project

Replace OPENTELEMETRY_VERSION with the latest release.

For Maven, add to your pom.xml dependencies:

<dependencies>
  <dependency>
    <groupId>io.opentelemetry.instrumentation</groupId>
    <artifactId>opentelemetry-ktor-2.0</artifactId>
    <version>OPENTELEMETRY_VERSION</version>
  </dependency>
</dependencies>

For Gradle, add to your dependencies:

implementation("io.opentelemetry.instrumentation:opentelemetry-ktor-2.0:OPENTELEMETRY_VERSION")

Usage

Initializing server instrumentation

Initialize instrumentation by installing the KtorServerTelemetry feature. You must set the OpenTelemetry to use with the feature.

val openTelemetry: OpenTelemetry = ...

embeddedServer(Netty, 8080) {
  install(KtorServerTelemetry) {
    setOpenTelemetry(openTelemetry)
  }
}

Initializing client instrumentation

Initialize instrumentation by installing the KtorClientTelemetry feature. You must set the OpenTelemetry to use with the feature.

val openTelemetry: OpenTelemetry = ...

val client = HttpClient {
  install(KtorClientTelemetry) {
    setOpenTelemetry(openTelemetry)
  }
}