Skip to content

fix: propagate W3C Trace Context from controller to agent pods#1312

Open
opspawn wants to merge 3 commits intokagent-dev:mainfrom
opspawn:fix/1295-trace-context-propagation
Open

fix: propagate W3C Trace Context from controller to agent pods#1312
opspawn wants to merge 3 commits intokagent-dev:mainfrom
opspawn:fix/1295-trace-context-propagation

Conversation

@opspawn
Copy link
Contributor

@opspawn opspawn commented Feb 15, 2026

Summary

Fixes #1295 — trace context (traceparent header) is not propagated from the controller to agent pods, breaking distributed tracing.

Changes

Go Controller (go/internal/controller/translator/agent/adk_api_translator.go): Added AppProtocol to agent Service port spec, enabling the gateway to forward trace headers to agent pods.

Python SDK (python/packages/kagent-core/src/kagent/core/tracing/_utils.py): Set up W3C TraceContext propagator to ensure incoming traceparent headers are properly extracted and propagated.

Golden test files: Updated all translator golden test outputs to include the new appProtocol field.

Signed-off-by: opspawn agent@opspawn.com

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.

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: opspawn <opspawn@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 15, 2026 17:21
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 attempts to fix distributed tracing by propagating W3C Trace Context headers from the controller to agent pods. The changes include configuring the W3C TraceContext propagator in the Python SDK and adding an appProtocol field to agent Service specs to enable gateway-based trace header forwarding.

Changes:

  • Configured W3C TraceContext propagator in Python SDK's tracing utilities
  • Added appProtocol: "kgateway.dev/a2a" to agent Service port specifications
  • Updated 24 golden test output files to reflect the new service configuration

Reviewed changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 2 comments.

File Description
python/packages/kagent-core/src/kagent/core/tracing/_utils.py Added W3C TraceContext propagator configuration for incoming/outgoing trace header extraction
go/internal/controller/translator/agent/adk_api_translator.go Added appProtocol field to agent Service ports for gateway-based routing
go/internal/controller/translator/agent/testdata/outputs/*.json Updated golden test outputs to include new appProtocol field and OTEL metrics environment variable

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

Comment on lines +69 to +71
# Set up W3C TraceContext propagator so incoming traceparent headers
# are extracted and outgoing requests carry them forward.
set_global_textmap(CompositeHTTPPropagator([TraceContextTextMapPropagator()]))
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

The new propagator configuration code lacks test coverage. Given that other modules in kagent-core have test files (test_a2a_config.py, test_hitl_handlers.py, etc.), consider adding tests to verify that:

  1. The W3C TraceContext propagator is properly configured when OTEL_TRACING_ENABLED=true
  2. The propagator correctly extracts traceparent headers from incoming requests
  3. The propagator properly injects trace headers into outgoing requests

Copilot uses AI. Check for mistakes.
Comment on lines +535 to +538
Name: "http",
Port: dep.Port,
TargetPort: intstr.FromInt(int(dep.Port)),
AppProtocol: ptr.To("kgateway.dev/a2a"),
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

The PR description states this change "enables the gateway to forward trace headers to agent pods," suggesting reliance on an external kgateway component. However, issue #1295 identifies two independent problems:

  1. Go Controller: A2ARequestHandler drops incoming HTTP headers (needs code changes in go/internal/httpserver/auth/authn.go)
  2. Python Agent: No W3C TraceContext propagator configured (addressed in this PR)

The issue specifically recommends modifying A2ARequestHandler to capture and inject trace headers (traceparent/tracestate) from incoming requests to outgoing requests to agent pods. This PR does not include those changes.

If the approach has changed to rely on kgateway instead of modifying A2ARequestHandler, this should be documented. Otherwise, trace headers will still be lost when the controller forwards requests to agent pods in deployments without kgateway (which is listed as "optional tooling" in the documentation).

Copilot uses AI. Check for mistakes.
Signed-off-by: opspawn <opspawn@users.noreply.github.com>
Signed-off-by: opspawn <opspawn@users.noreply.github.com>
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

1 participant

Comments