opentelemetry-java-instrume.../instrumentation/java-http-client/library
Jay DeLuca 94a8ffa7f4
Update links to not use search.maven.org (#14558)
2025-09-01 14:25:00 +03:00
..
src Fix java http client tests (#14043) 2025-06-16 16:45:14 +03:00
README.md Update links to not use search.maven.org (#14558) 2025-09-01 14:25:00 +03:00
build.gradle.kts Remove http stable semconv tests (#10087) 2023-12-21 08:30:26 -08:00

README.md

Library Instrumentation for Java HTTP Client

Provides OpenTelemetry instrumentation for Java HTTP Client.

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-java-http-client</artifactId>
    <version>OPENTELEMETRY_VERSION</version>
  </dependency>
</dependencies>

For Gradle, add to your dependencies:

implementation("io.opentelemetry.instrumentation:opentelemetry-java-http-client:OPENTELEMETRY_VERSION")

Usage

The instrumentation library contains an HttpClient wrapper that provides OpenTelemetry-based spans and context propagation.

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.httpclient.JavaHttpClientTelemetry;
import java.net.http.HttpClient;

import java.util.concurrent.ExecutorService;

public class JavaHttpClientConfiguration {

  //Use this HttpClient implementation for making standard http client calls.
  public HttpClient createTracedClient(OpenTelemetry openTelemetry) {
    return JavaHttpClientTelemetry.builder(openTelemetry).build().newHttpClient(createClient());
  }

  //your configuration of the Java HTTP Client goes here:
  private HttpClient createClient() {
    return HttpClient.newBuilder().build();
  }
}