open-telemetry / open-telemetry/opentelemetry-java-instrumentation

OkHttp3 library enhancement for gathering network phases timing via HTTP Span Events

Open
#14,835 1 comment 4 reactions 1 assignee View on GitHub

@surbhiia is already working on this.

Since Sep 30, 2025.

enhancement
Dominant language
Java
Stars
2.6k
Forks
1.2k
Avg merge
2d 18h
Merged PRs (30d)
228

Description

Is your feature request related to a problem? Please describe.

Current OkHttp3 instrumentation only captures total request duration. Performance issues appear as generic "slow requests" without identifying specific bottlenecks (DNS resolution, TLS handshake, server processing, etc.). OkHttp's EventListener provides perfect hooks for all network phases but isn't currently utilized.

Describe the solution you'd like

Enhance the existing OkHttp instrumentation to capture granular network timing phases as HTTP span events using OkHttp's EventListener API. This provides detailed timing breakdown (DNS, TCP, TLS, request/response phases) within HTTP spans for performance analysis.

OkHttp EventListener Method Proposed Span Event Description
dnsStart() http.dns.start DNS resolution begins
dnsEnd() http.dns.end DNS resolution completes
connectStart() http.connection.start TCP connection establishment begins
connectEnd() http.connection.end TCP connection establishment completes
secureConnectStart() http.tls.start TLS handshake begins (HTTPS only)
secureConnectEnd() http.tls.end TLS handshake completes (HTTPS only)
requestHeadersStart() http.request.header.start Request headers transmission begins
requestHeadersEnd() http.request.header.end Request headers transmission completes
requestBodyStart() http.request.body.start Request body upload begins
requestBodyEnd() http.request.body.end Request body upload completes
responseHeadersStart() http.response.header.start Response headers reception begins
responseHeadersEnd() http.response.header.end Response headers reception completes
responseBodyStart() http.response.body.start Response body download begins
responseBodyEnd() http.response.body.end Response body download completes

Additional callouts:

This enhancement transforms OkHttp spans from basic request timing to comprehensive network performance analysis, enabling actionable insights for application performance optimization.

Describe alternatives you've considered
Additional context

No response

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.