Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Android Instrumentation for OkHttp version 3.0 and higher

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.

Telemetry

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.

HTTP client span

  • 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 URL
    • http.response.status_code — response status code
    • network.protocol.version — protocol version (e.g. 1.1, 2 for HTTP/2)
    • server.address — logical server host
    • server.port — logical server port
    • network.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.

Quickstart

Add these dependencies to your project

Replace BYTEBUDDY_VERSION with the latest release.

Byte buddy compilation plugin

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'
}

Project dependencies

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.

Configuration

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.