opentelemetry-java-instrume.../instrumentation/okhttp/okhttp-3.0/library
Trask Stalnaker ffda571dd4
Remove deprecated HTTP library methods (#13150)
2025-02-01 08:05:03 +02:00
..
src Remove deprecated HTTP library methods (#13150) 2025-02-01 08:05:03 +02:00
README.md docs(okhttp): fix class name in README (#7578) 2023-01-15 09:10:05 -08:00
build.gradle.kts Add http/2 tests for okhttp3 (#11523) 2024-06-12 14:04:25 +03:00

README.md

Library Instrumentation for OkHttp version 3.0 and higher

Provides OpenTelemetry instrumentation for okhttp3.

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-okhttp-3.0</artifactId>
    <version>OPENTELEMETRY_VERSION</version>
  </dependency>
</dependencies>

For Gradle, add to your dependencies:

implementation("io.opentelemetry.instrumentation:opentelemetry-okhttp-3.0:OPENTELEMETRY_VERSION")

Usage

The instrumentation library provides an OkHttp Call.Factory implementation that wraps an instance of the OkHttpClient to provide OpenTelemetry-based spans and context propagation.

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.okhttp.v3_0.OkHttpTelemetry;
import okhttp3.Call;
import okhttp3.OkHttpClient;

import java.util.concurrent.ExecutorService;

public class OkHttpConfiguration {

  //Use this Call.Factory implementation for making standard http client calls.
  public Call.Factory createTracedClient(OpenTelemetry openTelemetry) {
    return OkHttpTelemetry.builder(openTelemetry).build().newCallFactory(createClient());
  }

  //your configuration of the OkHttpClient goes here:
  private OkHttpClient createClient() {
    return new OkHttpClient.Builder().build();
  }
}