Skip to content

Comments

fix: propagate trace context end-to-end for agent Services#1297

Open
syn-zhu wants to merge 2 commits intokagent-dev:mainfrom
syn-zhu:fix/agent-service-a2a-appprotocol
Open

fix: propagate trace context end-to-end for agent Services#1297
syn-zhu wants to merge 2 commits intokagent-dev:mainfrom
syn-zhu:fix/agent-service-a2a-appprotocol

Conversation

@syn-zhu
Copy link

@syn-zhu syn-zhu commented Feb 14, 2026

Summary

Three fixes to enable end-to-end W3C TraceContext propagation across the controller→agent boundary:

  1. AppProtocol on agent Services — Set appProtocol: kgateway.dev/a2a on the Service port created for each Agent CR so AgentGateway's A2A plugin can discover agent Services directly via protocol matching, rather than proxying through the kagent controller (which drops HTTP headers including traceparent).

  2. W3C TraceContext propagator in Python SDK — Configure the W3C TraceContext propagator in kagent-core tracing setup so agent pods correctly extract incoming traceparent headers and propagate them on outgoing requests.

  3. Trace header propagation in Go controller — The A2A server deserializes incoming HTTP requests into JSON-RPC params, discarding the original HTTP headers. When the controller forwards requests to agent pods via the A2A client, traceparent/tracestate are lost. Fix: capture W3C trace context headers from the incoming request into the Go context in the A2A auth middleware (A2AAuthenticator.Wrap), then inject them into outgoing requests in A2ARequestHandler.

All golden test outputs have been updated to include the new appProtocol field, including agent_with_passthrough (added in #1327).

Incorporates changes from opspawn@d9f2a3a.

Test plan

  • Golden tests updated and passing — all testdata/outputs/*.json files include appProtocol: "kgateway.dev/a2a" on Service ports
  • go test ./internal/httpserver/auth/... passes
  • Deploy agent, verify kubectl get svc <agent> -o jsonpath='{.spec.ports[0].appProtocol}' returns kgateway.dev/a2a
  • Verify AgentGateway A2A plugin discovers the Service
  • Send request with traceparent header through gateway → controller → agent pod, verify trace ID is preserved end-to-end

Closes #1295

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings February 14, 2026 01:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Agent manifest translation so that the Kubernetes Service created for each Agent CR sets an explicit appProtocol, enabling AgentGateway’s A2A plugin to discover and route directly to agent Services (preserving HTTP headers for distributed tracing).

Changes:

  • Set spec.ports[0].appProtocol: kgateway.dev/a2a on the per-Agent Service port.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@EItanya
Copy link
Contributor

EItanya commented Feb 16, 2026

Hey there, thanks for the PR, this is a great idea! You will need to update the goldens as well as sign your commits for us to merge this

@syn-zhu
Copy link
Author

syn-zhu commented Feb 20, 2026

Hey there, thanks for the PR, this is a great idea! You will need to update the goldens as well as sign your commits for us to merge this

Thanks! Just saw this now, but it looks like the issue was already fixed by opspawn@d9f2a3a :)

Gonna just close this PR, thanks!

@syn-zhu syn-zhu closed this Feb 20, 2026
@syn-zhu syn-zhu reopened this Feb 24, 2026
@syn-zhu
Copy link
Author

syn-zhu commented Feb 24, 2026

Oops @EItanya i realized the commit I linked wasn't actually a merged commit, but rather a branch. I've updated and reopened my PR to address the things you mentioned. Please lmk if there's anything else!

@syn-zhu syn-zhu force-pushed the fix/agent-service-a2a-appprotocol branch from 13799c1 to c2c5902 Compare February 24, 2026 11:12
@syn-zhu syn-zhu requested a review from peterj as a code owner February 24, 2026 11:12
@syn-zhu syn-zhu changed the title fix: set appProtocol on agent Services for A2A discovery fix: propagate trace context and enable A2A discovery for agent Services Feb 24, 2026
Two changes to enable end-to-end W3C TraceContext propagation:

1. Add AppProtocol "kgateway.dev/a2a" to agent Service port so
   AgentGateway can discover agent Services directly via kgateway
   protocol matching, rather than proxying through the controller.
   Update all golden test outputs to include the new appProtocol field.

2. Set up W3C TraceContext propagator in the Python agent SDK tracing
   configuration so agent pods correctly extract incoming traceparent
   headers and propagate them on outgoing requests.

Fixes kagent-dev#1295

Signed-off-by: Simon Zhu <simon.zhu@mongodb.com>
@syn-zhu syn-zhu force-pushed the fix/agent-service-a2a-appprotocol branch from c2c5902 to 256bbda Compare February 24, 2026 11:16
@syn-zhu syn-zhu changed the title fix: propagate trace context and enable A2A discovery for agent Services fix: propagate trace context end-to-end for agent Services Feb 24, 2026
…t pods

The A2A server deserializes incoming HTTP requests into JSON-RPC params,
discarding the original HTTP headers. When the controller forwards
requests to agent pods via the A2A client, trace context headers
(traceparent, tracestate) are lost, breaking distributed tracing.

Fix: capture W3C trace context headers from the incoming request into
the Go context in the A2A auth middleware, then inject them into
outgoing requests in the A2ARequestHandler. This closes the gap
between the A2A server (which strips headers) and the A2A client
(which constructs new HTTP requests).

Also update the agent_with_passthrough golden test (added in kagent-dev#1327)
to include the appProtocol field.

Signed-off-by: Simon Zhu <simon.zhu@mongodb.com>
@syn-zhu syn-zhu force-pushed the fix/agent-service-a2a-appprotocol branch from ffe2d68 to f965911 Compare February 24, 2026 11:28
@krisztianfekete
Copy link
Contributor

Hi @syn-zhu, Could you please test this locally on your end first? As it's Claude-generated code, a brief manual validation, e.g. such as posting before/after screenshots from a tracing tool would be the minimum step to ensure it's ready for contribution.

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.

Trace context (traceparent) not propagated from controller to agent pods

3 participants