Skip to content

OTel: chat span trace context is not propagated to outbound model requests (missing traceparent on llmInference.httpRequestStart / model HTTP headers) #5653

Backlog

Description

@TaoChenOSU

Describe the bug

When OpenTelemetry is enabled, Copilot CLI creates a chat span for every model call, but the outbound model request does not carry that span's W3C trace context. Neither the request headers nor the request metadata include a traceparent/tracestate.

As a result, any model backend or gateway that participates in distributed tracing cannot parent its spans under the CLI's chat span. Each model call starts a new, disconnected trace on the server side. One agent turn with N model calls therefore shows up as 1 + N traces in a tracing backend.

We hit this when embedding the CLI through the Python SDK (copilot package, 2.0.1) with a custom model request handler (CopilotClient(models={"request_handler": ...}), i.e. the llmInference.setProvider path). Trace context already flows correctly in the other direction:

  • The host's trace context is passed to the CLI on session.create / session.resume / session.send (traceparent/tracestate params), and the CLI's invoke_agent, chat and execute_tool spans are correctly parented under it.
  • hooks.invoke callbacks and hook.start session events carry a traceparent. For example, userPromptSubmitted, preToolUse and agentStop carry the invoke_agent span. External tool callbacks (external_tool.requested) also define traceparent/tracestate, and the SDK attaches them around the handler.

llmInference.httpRequestStart is the exception: it has no trace fields, and the forwarded headers contain no traceparent.

Affected version

Copilot CLI 1.0.114 (linux-x64), Python SDK 2.0.1.

Steps to reproduce the behavior

  1. Start the CLI through the Python SDK with telemetry enabled (OTLP exporter configured) and a custom models.request_handler that forwards requests to the model endpoint.
  2. Call session.send(...) while a host span is active, e.g. with trace dddddddddddddddddddddddddddddd04 and parent span 4444444444444444. Use a prompt that triggers at least one tool call, e.g. "Run 'echo hi' in bash, then tell me the output."
  3. Capture the CLI's stdout JSON-RPC frames, or inspect the requests reaching the model endpoint.

Observed in our capture (264 CLI→host messages for one turn):

  • Exported spans are correct: invoke_agent (parent 4444444444444444) → 2× chat gpt-5 and execute_tool bash, all in trace dddd…04.
  • Both llmInference.httpRequestStart frames have only these params: agentId, agentInvocationId, headers, interactionType, method, requestId, sessionId, transport, url.
  • Their headers are only accept, authorization, content-type, user-agent, x-initiator, x-interaction-type and x-stainless-*. There is no traceparent, tracestate or baggage.
  • Neither chat span ID appears anywhere in the CLI→host message stream. A traceparent value does appear in hooks.invoke and hook.start messages, but it always identifies the invoke_agent span (or the host's span for sessionStart).

Expected behavior

While a chat span is active, the model request it covers carries that span's W3C trace context. For example, traceparent: 00-<trace-id>-<chat-span-id>-<flags> (plus tracestate, if any), the same way an OTel-instrumented HTTP client would.

Preferably, for the external provider path:

  1. Add optional traceparent / tracestate fields to llmInference.httpRequestStart, consistent with external_tool.requested. In the SDKs, expose them on CopilotRequestContext and run send_request under that context (like the external-tool and hook handlers do with trace_context(...)). Host-side HTTP instrumentation then creates correctly parented child spans instead of new root traces.
  2. And/or inject traceparent / tracestate into the model request headers, so the default pass-through handler and direct (non-provider) requests propagate context without host changes.

Additional context

Activity

  1. added
    area:non-interactive
    on Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:non-interactive

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions