Mateusz Rzeszutek 59e2da5aa3 Extract HTTP client experimental metrics to a separate class (#8769) hai 1 ano
..
src 59e2da5aa3 Extract HTTP client experimental metrics to a separate class (#8769) hai 1 ano
README.md 3b4aeebd6d Ktor client instrumentation (#7982) %!s(int64=2) %!d(string=hai) anos
build.gradle.kts 3b4aeebd6d Ktor client instrumentation (#7982) %!s(int64=2) %!d(string=hai) anos

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 = initializeOpenTelemetryForMe()

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 = initializeOpenTelemetryForMe()

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