opentelemetry-java-instrume.../instrumentation/apache-httpclient/apache-httpclient-5.2/library
Jay DeLuca a26a32a739
Add support for library links in metadata (#14622)
2025-09-10 07:52:58 -07:00
..
src Rename method, use Telemetry instead of Metrics (#13574) 2025-03-25 11:03:32 +02:00
README.md Update links to not use search.maven.org (#14558) 2025-09-01 14:25:00 +03:00
build.gradle.kts Simplify metadata configuration flags (#14376) 2025-08-05 11:19:08 -07:00
metadata.yaml Add support for library links in metadata (#14622) 2025-09-10 07:52:58 -07:00

README.md

Library Instrumentation for Apache Http client version 5.2

Provides OpenTelemetry instrumentation for Apache Http Client 5.2.

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-apache-httpclient-5.2</artifactId>
    <version>OPENTELEMETRY_VERSION</version>
  </dependency>
</dependencies>

For Gradle, add to your dependencies:

implementation("io.opentelemetry.instrumentation:opentelemetry-apache-httpclient-5.2:OPENTELEMETRY_VERSION")

Usage

The instrumentation library provides the class ApacheHttpClientTelemetry that has a builder method and allows the creation of an instance of the HttpClientBuilder to provide OpenTelemetry-based spans and context propagation:

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.apachehttpclient.v5_2.ApacheHttpClientTelemetry;
import org.apache.hc.client5.http.classic.HttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;

public class ApacheHttpClientConfiguration {

  private OpenTelemetry openTelemetry;

  public ApacheHttpClientConfiguration(OpenTelemetry openTelemetry) {
    this.openTelemetry = openTelemetry;
  }

  // creates a new http client builder for constructing http clients with opentelemetry instrumentation
  public HttpClientBuilder createBuilder() {
    return ApacheHttpClientTelemetry.builder(openTelemetry).build().newHttpClientBuilder();
  }

  // creates a new http client with opentelemetry instrumentation
  public HttpClient newHttpClient() {
    return ApacheHttpClientTelemetry.builder(openTelemetry).build().newHttpClient();
  }
}