Repository navigation
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
There was a problem hiding this comment.
Informational-response callbacks reactivate the HTTP client span through Netty’s fire-method instrumentation, overriding the intended request-parent context and incorrectly parenting work started by those callbacks.
🤖 Bits Code Review · Commit f85595a
There was a problem hiding this comment.
More details
The PR preserves per-request context and baggage on pooled Netty 4.1 connections, clears completed exchanges, and retains WebSocket/CONNECT context as needed. The new callback marker fixes the earlier informational-response parenting defect while keeping the client span open for completion; no findings remain open.
🤖 Bits Code Review · Commit 4c7171b
Prefer the current request context over connection-creation context and clear completed exchanges before callbacks can reuse a channel. Restore the full callback context while retaining unfinished client spans across informational responses. Preserve context through CONNECT tunnel setup and WebSocket callbacks, and reset protocol state when HTTP requests resume. Cover request precedence, terminal callbacks, reentrant writes, informational responses, proxy tunnels, and WebSocket lifecycles.
9006e92 to
684d144
Compare
Check whether a connection-continuation attribute exists before taking or cancelling it. Netty's attr(key) creates an entry when absent, so the presence check avoids creating and immediately removing an empty attribute.
684d144 to
afcf500
Compare
There was a problem hiding this comment.
Shared Netty callback advice can discard baggage added by server handlers when they forward events with a child span active, causing downstream callbacks and outbound requests to lose that baggage.
🤖 Bits Code Review · Commit afcf500
Keep baggage added by server handlers while restoring the server span. Continue restoring the captured request context for client events such as TLS completion, which may arrive without that context active. Cover downstream handler and outbound request baggage propagation when a server handler forwards an event with a child span active.
There was a problem hiding this comment.
More details
The PR fixes stale request context on pooled Netty 4.1 clients and restores callback baggage. Completed HTTP exchanges clear their context. The latest commit preserves handler-added baggage during server forwarding and adds regression coverage. No review findings remain open. Validation was static; tests were not executed and production telemetry was excluded.
🤖 Bits Code Review · Commit d3be3ff
| } | ||
| if (finishSpan) { | ||
| // Keep the parent context for body chunks arriving after the client span finishes. | ||
| contextAttr.set(callbackContext); |
There was a problem hiding this comment.
P2 · Preserve handler-added baggage when forwarding streamed responses
When a 200 OK arrives as separate headers and body, this stores the request-parent context on the channel. A downstream handler can then add baggage, activate a child span, and forward the headers:
try (ContextScope ignored = Context.current().with(baggage).with(child).attach()) {
ctx.fireChannelRead(msg);
}FireAdvice sees the child span differ from the stored parent and attaches the entire saved context. The next handler sees no baggage added by the forwarding handler. This reproduced in both Netty test and latestDepTest with a DefaultHttpResponse followed by LastHttpContent. Could we preserve the live context while handlers forward a response, while still restoring the captured context for events such as TLS completion?
--- found with Codex
| final Context storedContext = contextAttr.get(); | ||
| final AgentSpan span = AgentSpan.fromContext(storedContext); | ||
| final boolean hasClientSpan = span != null && span != parent; | ||
| final Context callbackContext = storedContext == null ? parent : storedContext.with(parent); |
There was a problem hiding this comment.
P3 · Preserve active baggage when the channel has no stored exchange
With no stored exchange, attaching the fallback span as the entire context drops baggage already active on the caller. On a fresh client channel, I attached baggage and separately delivered an untracked response, fired an exception, and fired channelInactive. In both Netty test and latestDepTest, all three callbacks saw the expected noop span but read null for baggage.
Could we use Context.current().with(parent) when storedContext is absent, here and in finishExchange? That preserves the caller's baggage and still gives a bare noop span when the current context is root.
--- found with Codex
| return null; | ||
| } | ||
| return activateSpan(channelSpan); | ||
| if (ServerRequestContext.currentRequest(ctx.channel()) != null) { |
There was a problem hiding this comment.
Performance · Avoid allocating a server request attribute on client channels
When a client event reaches this branch, currentRequest reads the server request queue through attr(key).get(). On a fresh client-only channel, Netty creates an entry even though there is no server request. I checked hasAttr(AttributeKey.valueOf("datadog.server.request.contexts")) before and after forwarding the first client response. It changed from false to true in both Netty test and latestDepTest.
Could we check hasAttr before looking up the server request queue so the client path avoids creating the empty attribute?
--- found with Codex
AlexeyKuznetsov-DD
left a comment
There was a problem hiding this comment.
Pre-approving. Added couple of issues found by Codex.
What Does This Do
Preserve each request's context across Netty 4.1 HTTP client callbacks and prevent pooled connections from restoring context captured for an earlier request.
Response callbacks restore the full request context, including baggage, with the parent span active. Once an exchange completes, its context is cleared so later idle-channel callbacks no longer inherit the completed request's context.
Motivation
Pooled connections in the native ZIO HTTP client can propagate an earlier request's baggage and trace parent. The reproducer for #6772 exposed both connection-creation context overriding the current request and stale exchange state surviving connection reuse.
Additional Notes
Connection-creation context remains a fallback when the caller has only root or the bare noop span. Informational responses keep the exchange open, and WebSocket callbacks retain context across frames and recoverable errors. A new HTTP request resets the upgrade marker if HTTP resumes after a rejected handshake.
The
hasAttrguards avoid creating empty attributes during cleanup. Netty'sattr(key)creates an entry when absent, so an unconditionalattr(key).getAndRemove()orattr(key).remove()would allocate and immediately discard an entry when no connection continuation or WebSocket upgrade marker exists. Checking presence first avoids this churn on reused requests and ordinary HTTP channels, at the cost of an extra lookup when the attribute is present.Local validation covers baseline/latest Netty lifecycle tests, connection failures and WebSocket clients, plus a rebuilt-agent pooled ZIO reproducer checking legacy/W3C baggage and trace IDs with sequential and concurrent requests.
Netty 4.0 is outside this change's scope.