Network Instrumentation
Generates: Spans
Automatically instruments HTTP requests via OkHttp and HttpURLConnection using bytecode instrumentation at compile time.
Setup
Add the ByteBuddy plugin and the relevant instrumentation artifacts to your project.
Root build.gradle.kts
plugins {
id("net.bytebuddy.byte-buddy-gradle-plugin") version "BYTEBUDDY_VERSION"
}
Replace BYTEBUDDY_VERSION with the latest release >= 1.17.x.
Jetifier + Byte Buddy
With android.enableJetifier=true, Jetifier can break builds when it touches Byte Buddy (for example Unsupported class file major version). Don't jetify Byte Buddy — add to gradle.properties:
android.jetifier.ignorelist=net.bytebuddy
App build.gradle.kts
// OkHttp
implementation("org.dreamhorizon.instrumentation:okhttp3-library:LATEST_VERSION")
byteBuddy("org.dreamhorizon.instrumentation:okhttp3-agent:LATEST_VERSION")
// HttpURLConnection
implementation("org.dreamhorizon.instrumentation:httpurlconnection-library:LATEST_VERSION")
byteBuddy("org.dreamhorizon.instrumentation:httpurlconnection-agent:LATEST_VERSION")
Once added, HTTP requests are instrumented automatically — no code changes required.
What Gets Tracked
Every HTTP request captures:
| Attribute | Description | Always Present |
|---|---|---|
pulse.type | network.<status_code> — e.g. network.200, network.404, network.0 | ✅ |
http.method | HTTP method (GET, POST, etc.) | ✅ |
http.url | Full request URL | ✅ |
http.status_code | Response status code | ⚠️ If response received |
http.scheme | URL scheme (https) | ⚠️ If URL parseable |
http.host | Hostname | ⚠️ If URL parseable |
http.target | Request path | ⚠️ If URL parseable |
http.flavor | Protocol version (1.1, 2.0) | ⚠️ If available |
net.peer.name | Server hostname | ⚠️ If URL parseable |
net.peer.port | Port number | ⚠️ If specified |
http.request.body.size | Request body size in bytes | ⚠️ When Content-Length is present in header |
http.response.body.size | Response body size in bytes | ⚠️ When Content-Length is present in header |
On failure
| Attribute | Description |
|---|---|
error | true |
exception.type | Exception class name |
exception.message | Exception message |
Related
- Network Change — Track connectivity change events
- Global Attributes — Attributes attached to all spans