Status: development
The OpenTelemetry OkHttp instrumentation for Android instruments client-side requests made via OkHttp (version 3.0 +) okhttp3. It adds distributed tracing context, creates client HTTP spans, and records request/response metadata.
This instrumentation produces HTTP client spans using the OpenTelemetry HTTP semantic conventions. The span name is created via the HTTP span name extractor and attributes are provided by the OkHttp attributes getter.
- Type: Span
- Name: Determined by the HTTP span name extractor (typically
HTTP {method}or derived from the URL) - Description: Client-side HTTP request
- Common attributes (following OpenTelemetry HTTP semantic conventions):
http.request.method— request method (GET, POST, etc.)url.full— full request URLhttp.response.status_code— response status codenetwork.protocol.version— protocol version (e.g.1.1,2for HTTP/2)server.address— logical server hostserver.port— logical server portnetwork.peer.address/network.peer.port— connection endpoint, when available- Captured request/response headers per configuration (
http.request.header.<name>/http.response.header.<name>)
If a request fails, the span is ended and the error is recorded.
Replace BYTEBUDDY_VERSION with the latest
release.
This plugin leverages Android's Transform API to instrument bytecode at compile time. You can find more info on its repo page.
plugins {
id 'net.bytebuddy.byte-buddy-gradle-plugin' version 'BYTEBUDDY_VERSION'
}implementation("io.opentelemetry.android.instrumentation:okhttp3-library:1.6.0-alpha")
byteBuddy("io.opentelemetry.android.instrumentation:okhttp3-agent:1.6.0-alpha")After adding the plugin and the dependencies to your project, your OkHttp requests will be traced automatically.
You can configure the automatic instrumentation by using the setters from the OkHttpInstrumentation instance provided via the AndroidInstrumentationLoader as shown below:
OkHttpInstrumentation instrumentation = AndroidInstrumentationLoader.getInstrumentation(OkHttpInstrumentation.class);
// Call `instrumentation` setters.Note
You must make sure to apply any configurations before initializing your OpenTelemetryRum instance (i.e. calling OpenTelemetryRum.builder()...build()). Otherwise your configs won't be taken into account during the RUM initialization process.