Skip to content

[FEATURE] W3C trace context and baggage propagation to subprocesses, span ingestion via OTLP #904

Closed
inference-gateway/docs
#394

Description

@edenreich

Summary

Today a bash command or skill script is one opaque execute_tool Bash span: total duration only.
Make subprocess timing cooperative and open-standard: the CLI propagates context to the
subprocess using the W3C conventions, and the subprocess reports spans back using OTLP - no
proprietary formats, so anything already instrumented with an OTel SDK (or otel-cli) integrates
with zero custom code.

Context in (W3C). When telemetry is enabled, the Bash tool and the skills runner export to
the subprocess environment:

  • TRACEPARENT / TRACESTATE - W3C Trace Context (00-<trace_id>-<tool_span_id>-01), the
    de-facto env-var propagation convention understood by otel-cli and OTel SDK shell integrations.
  • BAGGAGE - W3C Baggage carrying request-scoped context, e.g.
    infer.session.id=...,infer.tool.call.id=.... Per the OTel baggage guidance: baggage flows
    downstream only, it is a separate store from span attributes (children decide what to stamp),
    and it must never carry secrets.

Spans out (OTLP). No bespoke return channel - the child exports spans the same way every
OTel-instrumented tool already does:

  1. Collector configured (telemetry.otlp.endpoint / OTEL_EXPORTER_OTLP_ENDPOINT): the CLI
    passes the endpoint and headers through to the child environment. Child spans go straight to
    the collector and stitch to the CLI's trace via TRACEPARENT parentage. Zero CLI runtime work.
  2. Local-first (no collector): the CLI runs an ephemeral localhost OTLP/HTTP receiver for the
    session and sets OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:<port> in the child env.
    Received spans are persisted into the per-session local trace store (and forwarded when a
    remote is also configured). go.opentelemetry.io/proto/otlp is already a dependency.

Plain shell scripts need no SDK: otel-cli span --name "go test" -- go test ./... reads
TRACEPARENT and speaks OTLP. The /traces viewer (#903) then shows:

execute_tool Bash                          27.5s
|-- go build                                4.7s
`-- go test ./internal/...                 22.4s

Subagent stitching. Subagents run as infer agent subprocesses (Agent tool,
channels-manager). StartSession honors an inherited TRACEPARENT, so a child session's whole
trace nests under the parent's execute_tool Agent span - same convention, no extra protocol.

Non-goals: proprietary span file formats or CLI-specific return channels; capturing argv/xtrace
(secret-leak risk) - reporting granularity is always the subprocess's choice.

Builds on the traces engine from #893 / PR #901; renders via #903.

Acceptance Criteria

  • Bash tool and skills runner export TRACEPARENT/TRACESTATE (W3C Trace Context, current tool span) and BAGGAGE (W3C Baggage: session id, tool call id; no sensitive values) when telemetry is enabled; none are set when disabled.
  • With an OTLP endpoint configured, the endpoint and headers are passed through to the subprocess environment so child spans stitch in the backend via parentage.
  • Without a configured endpoint, an ephemeral localhost OTLP/HTTP receiver accepts child spans and persists them into the per-session local trace store; defensive limits (span count, payload size) and receiver failures never fail the tool.
  • infer agent honors an inherited TRACEPARENT so a subagent session span parents under the caller's execute_tool Agent span (one cross-process trace).
  • The contract is documented with otel-cli and OTel SDK examples; [DOCS] follow-up filed against inference-gateway/docs.

Activity

  1. added
    enhancement
    on Jul 13, 2026
  2. moved this to Todo in 2026on Jul 13, 2026
  3. changed the title [-][FEATURE] Propagate trace context to subprocesses and ingest trace bags[/-] [+][FEATURE] W3C trace context and baggage propagation to subprocesses, span ingestion via OTLP[/+] on Jul 13, 2026
  4. moved this from Todo to In progress in 2026on Jul 13, 2026
  5. moved this from In progress to QA in 2026on Jul 13, 2026
  6. moved this from QA to Done in 2026on Jul 14, 2026
  7. added a commit that references this issue on Jul 16, 2026
    d1c09da
  8. inference-gateway-releaser commented on Jul 16, 2026

    @inference-gateway-releaser
    Contributor

    🎉 This issue has been resolved in version 0.147.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

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

    enhancementreleased

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions