opentelemetry-java-instrume.../instrumentation/apache-httpclient/apache-httpclient-5.2/library
Elbio Caetano 27c85e208e
feat: instrumentation for apache httpclient 5 (#10100)
Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
2024-01-31 07:27:25 +02:00
..
src feat: instrumentation for apache httpclient 5 (#10100) 2024-01-31 07:27:25 +02:00
README.md feat: instrumentation for apache httpclient 5 (#10100) 2024-01-31 07:27:25 +02:00
build.gradle.kts feat: instrumentation for apache httpclient 5 (#10100) 2024-01-31 07:27:25 +02: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 ApacheHttpClient5Telemetry 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.ApacheHttpClient5Telemetry;
import org.apache.hc.client5.http.classic.HttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;

public class ApacheHttpClient5Configuration {

  private OpenTelemetry openTelemetry;

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

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

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