Skip to content

Commit 6f5b2f2

Browse files
docs(instrumentation): add telemetry descriptions for httpurlconnection, okhttp3 and okhttp3-websocket (Issue #742) (#1242)
* docs(instrumentation/httpurlconnection): add telemetry section to README and align structure with slowrendering/startup style * docs(instrumentation/okhttp3): add telemetry section to README * docs(instrumentation/okhttp3-websocket): add telemetry section to README * Apply suggestions from code review Co-authored-by: jason plumb <[email protected]> --------- Co-authored-by: jason plumb <[email protected]>
1 parent 55b4470 commit 6f5b2f2

File tree

3 files changed

+106
-6
lines changed

3 files changed

+106
-6
lines changed

instrumentation/httpurlconnection/README.md

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,86 @@
11
# Android Instrumentation for URLConnection, HttpURLConnection and HttpsURLConnection
22

3-
## Status : Experimental
3+
Status: development
4+
5+
The OpenTelemetry HttpUrlConnection instrumentation for Android will automatically
6+
instrument client-side usage of:
47

5-
Provides OpenTelemetry instrumentation for:
68
- [URLConnection](https://developer.android.com/reference/java/net/URLConnection)
79
- [HttpURLConnection](https://developer.android.com/reference/java/net/HttpURLConnection)
810
- [HttpsURLConnection](https://developer.android.com/reference/javax/net/ssl/HttpsURLConnection)
911

12+
The instrumentation operates by intercepting application calls to the APIs that
13+
initiate or read from network connections. It performs three primary actions:
14+
15+
- adds distributed tracing context to outgoing requests
16+
- creates and ends client HTTP spans
17+
- records request/response metadata and exceptions
18+
19+
[See the Android URLConnection documentation](https://developer.android.com/reference/java/net/URLConnection) for reference.
20+
21+
## Telemetry
22+
23+
This instrumentation produces HTTP client spans using the OpenTelemetry HTTP semantic
24+
conventions. The instrumentation scope (instrumentation library name) is
25+
`io.opentelemetry.android.http-url-connection`.
26+
27+
### HTTP client span
28+
29+
This instrumentation creates a span for each HTTP request. Spans are ended when one of
30+
the following occurs: the response stream is fully read, the stream is closed,
31+
`disconnect()` is called, or an exception occurs while interacting with the connection.
32+
33+
- Type: Span
34+
- Name: Determined by the HTTP span name extractor (typically `HTTP {method}` or derived from the URL)
35+
- Description: Client-side HTTP request
36+
- Attributes (following OpenTelemetry [HTTP semantic conventions](https://opentelemetry.io/docs/specs/semconv/http/http-spans/)):
37+
- `http.method` — request method (GET, POST, etc.)
38+
- `http.url` — full URL
39+
- `http.target`, `http.host`, `http.scheme` — parts of the request URL when available
40+
- `http.status_code` — response status code
41+
- `http.flavor` — protocol (e.g. `1.1`)
42+
- `net.peer.name` — server host
43+
- `net.peer.port` — server port
44+
- Request and response headers captured according to configuration: `http.request.header.*` / `http.response.header.*`
45+
46+
If the request throws an IOException, the span is ended and the exception is recorded.
47+
48+
### Configuration impact on telemetry
49+
50+
You can customize which request and response headers are captured and other behavior via
51+
the `HttpUrlInstrumentation` setters exposed through `AndroidInstrumentationLoader`.
52+
These settings are applied when `HttpUrlConnectionSingletons.configure(...)` is called
53+
during instrumentation setup. See the `Configurations` section above for how to access
54+
the instrumentation instance.
55+
56+
### Distributed tracing propagation
57+
58+
The instrumentation injects the configured context propagators into the request using
59+
request properties (via a TextMap setter), allowing distributed tracing across services.
60+
1061
## Quickstart
1162

1263
### Overview
1364

1465
This plugin enhances the Android application host code by instrumenting all critical APIs (specifically those that initiate a connection). It intercepts calls to these APIs to ensure the following actions are performed:
66+
1567
- Context is added for distributed tracing before actual API is called (i.e before connection is initiated).
1668
- Traces and spans are generated and properly closed.
1769
- Any exceptions thrown are recorded.
1870

1971
A span associated with a given request is concluded in the following scenarios:
72+
2073
- When the getInputStream()/getErrorStream() APIs are called, the span concludes after the stream is fully read, an IOException is encountered, or the stream is closed.
2174
- When the disconnect API is called.
2275

2376
Spans won't be automatically ended and reported otherwise. If any of your URLConnection requests do not call the span concluding APIs mentioned above, refer the section entitled ["Scheduling Harvester Thread"](#scheduling-harvester-thread). This section provides guidance on setting up a recurring thread that identifies unreported, idle connections and ends/reports any open spans associated with them. Idle connections are those that have been read from previously but have been inactive for a particular configurable time interval (defaults to 10 seconds).
2477

2578
> The minimum supported Android SDK version is 21, though it will also instrument APIs added in the Android SDK version 26 when running on devices with API level 26 and above.
26-
2779
> If your project's minSdk is lower than 26, then you must enable
2880
> [corelib desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring).
2981
>
3082
> Further, in order to run the app built on debug, you need to add the following property in `gradle.properties` file:
83+
>
3184
> - If AGP <= 8.3.0, set `android.enableDexingArtifactTransform=false`
3285
> - If AGP > 8.3.0, set `android.useFullClasspathForDexingTransform=true`
3386
>
@@ -61,6 +114,7 @@ byteBuddy("io.opentelemetry.android.instrumentation:httpurlconnection-agent:0.15
61114
#### Scheduling Harvester Thread
62115

63116
To schedule a periodically running thread to conclude/report spans on any unreported, idle connections, add the below code in the function where your application starts ( that could be onCreate() method of first Activity/Fragment/Service):
117+
64118
```java
65119
HttpUrlInstrumentation instrumentation = AndroidInstrumentationLoader.getInstrumentation(HttpUrlInstrumentation.class);
66120
instrumentation.setConnectionInactivityTimeoutMs(customTimeoutValue); //This is optional. Replace customTimeoutValue with a long data type value which denotes the connection inactivity timeout in milli seconds. Defaults to 10000ms
@@ -72,6 +126,7 @@ Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(instrumentat
72126
- It is efficient to run the harvester thread at the same time interval as the connection inactivity timeout used to identify the connections to be reported. `instrumentation.getReportIdleConnectionInterval()` is the API to get the same connection inactivity timeout interval (milliseconds) you have configured or the default value of 10000ms if not configured.
73127

74128
#### Other Optional Configurations
129+
75130
You can optionally configure the automatic instrumentation by using the setters from [HttpUrlInstrumentation](library/src/main/java/io/opentelemetry/instrumentation/library/httpurlconnection/HttpUrlInstrumentation.kt)
76131
instance provided via the AndroidInstrumentationLoader as shown below:
77132

instrumentation/okhttp3-websocket/README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
# Android Instrumentation for OkHttp Websocket version 3.0 and higher
22

3-
## Status: development
3+
Status: development
4+
5+
The OpenTelemetry OkHttp WebSocket instrumentation for Android instruments
6+
client-side OkHttp WebSocket usage. It creates telemetry for websocket lifecycle
7+
events and can capture metadata about connections and messages.
48

59
Provides OpenTelemetry instrumentation for [okhttp3 websockets](https://square.github.io/okhttp/3.x/okhttp/okhttp3/WebSocket.html).
610

11+
## Telemetry
12+
13+
This instrumentation primarily produces events/spans related to the WebSocket
14+
connection lifecycle (connect, close, errors) and can record attributes such as
15+
the peer host/port and any configured headers.
16+
17+
* Type: Span / Event (connection lifecycle)
18+
* Name: Determined by instrumentation (e.g. `WebSocket connect` / `WebSocket close`)
19+
* Attributes (examples):
20+
* `net.peer.name` — server host
21+
* `net.peer.port` — server port
22+
* `http.url` — the websocket URL
23+
* Captured headers per configuration
24+
25+
If a websocket connection errors, the instrumentation records the error on the
26+
connection telemetry.
27+
728
## Installation
829

930
### Applying the Byte Buddy plugin

instrumentation/okhttp3/README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
11
# Android Instrumentation for OkHttp version 3.0 and higher
22

3-
## Status: development
3+
Status: development
44

5-
Provides OpenTelemetry instrumentation for [okhttp3](https://square.github.io/okhttp/).
5+
The OpenTelemetry OkHttp instrumentation for Android instruments client-side requests
6+
made via OkHttp (version 3.0 +) [okhttp3](https://square.github.io/okhttp/). It adds distributed tracing context,
7+
creates client HTTP spans, and records request/response metadata.
8+
9+
## Telemetry
10+
11+
This instrumentation produces HTTP client spans using the OpenTelemetry [HTTP semantic
12+
conventions](https://opentelemetry.io/docs/specs/semconv/http/http-spans/). The span name is created via the HTTP span name extractor and attributes
13+
are provided by the OkHttp attributes getter.
14+
15+
### HTTP client span
16+
17+
* Type: Span
18+
* Name: Determined by the HTTP span name extractor (typically `HTTP {method}` or derived from the URL)
19+
* Description: Client-side HTTP request
20+
* Common attributes (following OpenTelemetry HTTP semantic conventions):
21+
* `http.method` — request method (GET, POST, etc.)
22+
* `http.url` — full URL
23+
* `http.status_code` — response status code
24+
* `http.flavor` — protocol (e.g. `1.1`)
25+
* `net.peer.name` — server host
26+
* `net.peer.port` — server port
27+
* Captured request/response headers per configuration
28+
29+
If a request fails, the span is ended and the error is recorded.
630

731
## Quickstart
832

0 commit comments

Comments
 (0)