Skip to content

Send W3C trace context on agent model calls - #131

Open
dcmcand wants to merge 1 commit into
mainfrom
feat/agent-client-trace-context
Open

dcmcand wants to merge 1 commit into
mainfrom
feat/agent-client-trace-context

Conversation

@dcmcand

@dcmcand dcmcand commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Slice 4: Tapas model calls carry W3C trace context

Every model call the agent proxy makes now carries traceparent and tracestate, never baggage, and shows up as a standard HTTP client span. Streaming, timeouts and the fixed header set are otherwise unchanged. This is the Tapas side of gateway tracing in the LLM serving pack: once the pack's AI Gateway exports spans, a Tapas agent's model call becomes one trace with the Tapas server span, the Tapas client span and the gateway span.

Design: gateway and vLLM OpenTelemetry tracing (nebari-dev/llm-serving-pack#315, traces #148). The spec and plan are kept locally; this PR is Slice 4 of 8. The agent-session-id pass-through is not in this PR; it lands with its first sender in #127.
Contracts touched: the headers a model call from agentproxy carries to the provider; aisettings.agentClient(timeout, guard) *http.Client (same signature, wrapped transport).
Depends on: none.

What changes

  • agentClient wraps today's transport (guarded or not) in otelhttp.NewTransport with only propagation.TraceContext{}. The server handler uses TraceContext plus Baggage, so passing the propagator explicitly is what keeps baggage, which can name the caller, from reaching the provider.
  • With telemetry on, an agent's valid traceparent is continued with Tapas's own client span id, and a call without one starts its own trace. With telemetry off, an agent's valid traceparent and tracestate go on as they came, and a call without one sends no trace context.
  • agentproxy is untouched. It still sets only Content-Type, Authorization and, for a stream, Accept.
  • Docs: a contract entry for the headers a model call carries, two patterns, and a paragraph in the admin configuration page.

Validation

Step Command Result
unit go test -count=1 ./internal/ai/... ./internal/telemetry/... pass
neighbours go test -count=1 ./internal/gateway/... pass
full make test 2 packages fail, and both fail the same way on main c7fa2b9: internal/files TestDecodeListingByteCap (local go1.27.4) and test/imagetag (shasum not installed here)
lint go vet ./... clean. golangci-lint reports 91 issues, the same count as main, none on new lines

TestAgentCallCarriesOnlyTraceContext runs the real Proxy and agentClient against a fake provider. The agent request carries its own token, a cookie, baggage and a custom header. For six cases (telemetry on or off; a valid, missing or malformed incoming traceparent; streamed or not) it asserts the exact set of header names the provider receives, that Authorization is the configured key, the trace and span ids, and the stream body. Switching the transport to TraceContext plus Baggage fails every case.

Open item

The comment at internal/ai/agentproxy/agentproxy.go:198 ("Only these headers go out") no longer lists everything sent, because the transport now adds the trace headers. I left the file alone, since the design keeps agentproxy unchanged. We should decide whether to update that comment here or in #127.

agentClient now wraps its transport in otelhttp.NewTransport with only
the TraceContext propagator. Each provider call becomes an HTTP client
span of the agent's request, and the provider receives traceparent and
tracestate, so a gateway that traces (the llm-serving-pack's AI Gateway)
continues the same trace. baggage never goes out: the transport does not
use the server's TraceContext+Baggage propagators. The guard,
ResponseHeaderTimeout and the absence of a whole-request timeout are
unchanged.

TestAgentCallCarriesOnlyTraceContext drives the real Proxy and agentClient
against a fake provider and asserts the exact header set for six cases:
telemetry on or off, with a valid, missing or malformed incoming
traceparent, streamed and not. Each case gets its own tracer provider
through the handler rather than the global one.

Docs: a contract entry for the headers a model call carries to the
provider, two patterns, and a paragraph in the admin configuration page.

Refs nebari-dev/llm-serving-pack#315, nebari-dev/llm-serving-pack#148

This branch was successfully deployed

1 active deployment
branch-images — a0f8e614 Deployed Dec 4, 2026 by dcmcand via Copy to Quay #28
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.

1 participant