opentelemetry-java-instrume.../instrumentation/ktor/ktor-2.0/library
Mateusz Rzeszutek 65ee9510f5
Rename the `instrumentation-api-semconv` module into `instrumentation-api-incubator` (#9985)
2023-12-04 08:28:10 +01:00
..
src Rename the `instrumentation-api-semconv` module into `instrumentation-api-incubator` (#9985) 2023-12-04 08:28:10 +01:00
README.md Small library doc updates (#9868) 2023-11-14 14:33:05 -08:00
build.gradle.kts Compile ktor library instrumentation for earlier kotlin version (#9661) 2023-10-12 07:59:06 -07:00

README.md

Library Instrumentation for Ktor version 2.0 and higher

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 KtorServerTracing feature. You must set the OpenTelemetry to use with the feature.

val openTelemetry: OpenTelemetry = ...

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

Initializing client instrumentation

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

val openTelemetry: OpenTelemetry = ...

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