Skip to content

Restore caller context at Jetty javaagent invocation boundaries - #20959

Closed
trask with Copilot wants to merge 6 commits into
mainfrom
copilot/change-jetty-instrumentation-approach
Closed

trask with Copilot wants to merge 6 commits into
mainfrom
copilot/change-jetty-instrumentation-approach

Conversation

Copilot AI commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Restore captured caller context at Jetty’s request dispatch and content-consumption boundaries instead of proxying application request listeners, providers, or iterators. Scope the change to the Jetty 9.2 javaagent module; library instrumentation remains unchanged.

  • Context: Capture the full caller context before starting the CLIENT span, including custom values without a caller span. Preserve nested context choices and restore callback-thread context on exceptional exits.
  • Lifecycle: Keep CLIENT propagation separate from callback execution. Preserve redirect/authentication suppression, completion ordering, and request reuse.
  • Regression coverage: Exercise ordinary and deferred bodies, chunk success/failure callbacks, response-triggered aborts, object identity, and independently instrumented outgoing work.
  • Remaining gap: Late offers to an already-failed deferred provider invoke failure callbacks without a request-associated boundary; attribution remains unresolved under the stated constraints.

@opentelemetry-pr-dashboard

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-10-25 18:33 UTC

Move out of draft to request review.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

Copilot AI and others added 3 commits October 25, 2026 18:43
Co-authored-by: trask <218610+trask@users.noreply.github.com>
Co-authored-by: trask <218610+trask@users.noreply.github.com>
Co-authored-by: trask <218610+trask@users.noreply.github.com>
Copilot AI changed the title [WIP] Update Jetty 9.2 javaagent instrumentation to restore captured caller context Restore caller context at Jetty javaagent invocation boundaries Oct 25, 2026
Copilot AI requested a review from trask October 25, 2026 19:13
@trask
trask requested a balanced review from Copilot October 25, 2026 19:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Request reuse accumulates context-retaining listeners, and cross-request callback reentry can overwrite explicitly selected context.

2 open issues
What changed in this PR

This PR restores caller context at Jetty 9.2 javaagent request and content-consumption boundaries without replacing application request listeners, providers, or iterators. Library instrumentation remains unchanged.

Changes:

  • Separates caller-context restoration from CLIENT span propagation and completion.
  • Adds boundary instrumentation for request dispatch, body consumption, and aborts.
  • Adds regression coverage for nested callbacks, deferred bodies, protocol followups, and request reuse.
File Description
instrumentation/​jetty-httpclient/​jetty-httpclient-9.2/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​jetty/​httpclient/​v9_2/​JettyCallerContextTest.java Tests caller context, object identity, and request lifecycle behavior.
instrumentation/​jetty-httpclient/​jetty-httpclient-9.2/​javaagent/​src/​main/​java/​io/​opentelemetry/​javaagent/​instrumentation/​jetty/​httpclient/​v9_2/​JettyRequestContext.java Manages request context, span completion, and protocol continuations.
instrumentation/​jetty-httpclient/​jetty-httpclient-9.2/​javaagent/​src/​main/​java/​io/​opentelemetry/​javaagent/​instrumentation/​jetty/​httpclient/​v9_2/​JettyRequestBoundaryInstrumentation.java Restores context around request notifications and aborts.
instrumentation/​jetty-httpclient/​jetty-httpclient-9.2/​javaagent/​src/​main/​java/​io/​opentelemetry/​javaagent/​instrumentation/​jetty/​httpclient/​v9_2/​JettyHttpSenderInstrumentation.java Associates exchanges with caller context and scopes sending.
instrumentation/​jetty-httpclient/​jetty-httpclient-9.2/​javaagent/​src/​main/​java/​io/​opentelemetry/​javaagent/​instrumentation/​jetty/​httpclient/​v9_2/​JettyHttpContentInstrumentation.java Restores context during content consumption and cleanup.
instrumentation/​jetty-httpclient/​jetty-httpclient-9.2/​javaagent/​src/​main/​java/​io/​opentelemetry/​javaagent/​instrumentation/​jetty/​httpclient/​v9_2/​JettyHttpClient9InstrumentationModule.java Registers the new boundary instrumentations.
instrumentation/​jetty-httpclient/​jetty-httpclient-9.2/​javaagent/​src/​main/​java/​io/​opentelemetry/​javaagent/​instrumentation/​jetty/​httpclient/​v9_2/​JettyHttpClient9Instrumentation.java Integrates request state, response wrapping, and continuation handling.
instrumentation/​jetty-httpclient/​jetty-httpclient-9.2/​javaagent/​src/​main/​java/​io/​opentelemetry/​javaagent/​instrumentation/​jetty/​httpclient/​v9_2/​JettyContentContext.java Stores caller context and manages reentrant callback scopes.

Review effort: Balanced

Co-authored-by: trask <218610+trask@users.noreply.github.com>
Copilot AI requested a review from trask October 25, 2026 20:09
@trask
trask requested a balanced review from Copilot October 25, 2026 20:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Reentrant context restoration and protocol-completion ordering across supported Jetty versions require final human compatibility review.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Low severity Add test for producer-thread exception context cleanup

instrumentation/​jetty-httpclient/​jetty-httpclient-9.2/​javaagent/​src/​main/​java/​io/​opentelemetry/​javaagent/​instrumentation/​jetty/​httpclient/​v9_2/​JettyHttpContentInstrumentation.java:58

[Testing] The new tests exercise failed requests, but none throws out of a scoped content method: the abort and upload-failure cases invoke failed(...) normally. Please add an installed-agent test where an iterator or chunk callback throws on a producer thread with an unrelated context, and assert that the thread's span/custom values are restored afterward. Exceptional cleanup of the current context and activeCallback frame is a distinct lifecycle guarantee that the existing failure tests do not cover.

2 resolved since last review

Review effort: Balanced

Co-authored-by: trask <218610+trask@users.noreply.github.com>
Copilot AI requested a review from trask October 25, 2026 20:36
@trask
trask requested a balanced review from Copilot October 25, 2026 20:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Reentrant callbacks, cross-thread restoration, and protocol completion during request reuse warrant final human review across supported Jetty versions.

No open issues 🎉

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants