Skip to content

feat(telemetry): propagate W3C trace context to subprocesses and ingest child spans via OTLP - #909

Merged
edenreich merged 11 commits into
mainfrom
feat/trace-propagation
Jul 16, 2026
Merged

edenreich merged 11 commits into
mainfrom
feat/trace-propagation

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

Summary

Closes #904.

Today a bash command, skill script, or subagent is one opaque execute_tool span with a total duration only. This PR makes subprocess timing cooperative and open-standard: the CLI propagates context out using pure W3C conventions, and children report spans back via standard OTLP. No proprietary formats or env vars are introduced, so anything already instrumented with an OTel SDK (or otel-cli) integrates with zero custom code. Local storage remains the default sink; a remote OTLP collector stays opt-in via the existing telemetry.otlp.endpoint config.

Context out (W3C). The telemetry tool-span decorator computes TRACEPARENT/TRACESTATE (from the live execute_tool span, via the standard OTel propagation.TraceContext propagator) and BAGGAGE (infer.session.id, infer.tool.call.id — no secrets) once per tool span and carries the result on the context. The Bash tool sets it on the child env (one assignment covers foreground, streaming, and detached — they share the same exec.Cmd), and headless subagents get it through subagentExtraEnv. When telemetry is disabled the decorator is absent, so children get no trace env at all. Skills run through the Bash tool and are covered transitively.

Spans in (OTLP). The OTLP sink for children is resolved in Recorder.ChildEnv: a config-file endpoint is passed through explicitly as OTEL_EXPORTER_OTLP_ENDPOINT/OTEL_EXPORTER_OTLP_HEADERS; an env-configured endpoint is simply inherited; and with no endpoint at all, a lazy ephemeral loopback OTLP/HTTP receiver accepts POST /v1/traces (protobuf) and persists each span into the per-session local trace file in the stdouttrace stub shape the /traces viewer (#903 / #908) reads. Defensive limits: 4 MiB per request, 5000 spans per session, always responds 200 — receiver failures never fail the tool. A lockedWriter shared between the stdouttrace exporter and the receiver serializes trace-file writes, eliminating interleaving by construction.

Subagent stitching. StartSession now extracts an inherited TRACEPARENT/TRACESTATE from the environment (standard extract; no env means unchanged behavior), so a subagent's session span parents under the caller's execute_tool Agent span — one cross-process trace. Since the parent points the child at its loopback receiver, the child's existing OTLP export path lights up with zero child-side code and its spans land in the parent's session file. Verified end to end against the mock gateway:

session (standard, success)            152ms
|-- chat openai/gpt-4o                   5ms
|-- execute_tool Agent                  89ms
|   `-- session (readonly, success)     52ms
|       |-- chat openai/gpt-4o           5ms
|       `-- chat openai/gpt-4o          13ms
`-- chat openai/gpt-4o                  12ms

A2A remote servers. All six adk client construction sites now use telemetry.NewA2AClient, which wraps the HTTP transport with a RoundTripper injecting traceparent/tracestate/baggage headers from the request context. This is context-out only: whether a remote agent records spans and where they go is its business (shared-collector scenario); its spans do not land in our local store.

No new config keys and no new go.mod modules: otel/propagation and otel/baggage live in the already-required go.opentelemetry.io/otel root module; go.opentelemetry.io/proto/otlp and google.golang.org/protobuf merely moved from indirect to direct.

Known limitations

  • Interactive (tmux-pane) subagents do not receive the trace env; only headless subagents stitch. Deliberate: an interactive pane is a user-driven infer chat REPL without completion semantics.
  • Detached/background bash children that outlive the parent process lose late spans silently once the parent's receiver goes away, consistent with "receiver failures never fail the tool".
  • A subagent's spans exist both in its own session file and in the parent's (via the receiver). Nothing double-counts: the viewer is per-session-file, and infer stats reads metrics files, which are untouched.

Testing

  • internal/telemetry/propagation_test.go: ChildEnv matrix (nil recorder, no span, loopback default, config endpoint passthrough, env-endpoint inheritance), baggage members, header injection on traced vs untraced requests.
  • internal/telemetry/receiver_test.go: real OTLP protobuf export ingested and nested under the tool span by LoadTraceTree; garbage payloads and /v1/metrics accepted and dropped; session span cap enforced.
  • recorder test: inherited TRACEPARENT becomes the session span's parent; unset keeps a zero parent.
  • bash tool test: trace env present in the child exactly when the context carries it.
  • Full suite, go test -race on the touched packages, and golangci-lint all pass. Manual end-to-end run against the mock gateway shown above.

Cross-repo impact

Docs only: follow-up [DOCS] issue filed against inference-gateway/docs to document the propagation contract with otel-cli and OTel SDK examples. No schema, gateway, or operator changes — all env vars used are standard OTel/W3C ones.

…ransport function

The ADK v0.21.0 now supports Config.Transport natively, so callers construct the client inline. Removes the internal/a2a wrapper package entirely and replaces it with a public PropagationTransport(http.RoundTripper) constructor.
@edenreich

Copy link
Copy Markdown
Contributor Author

@infer adk version 0.22.0 just got released, can you create an example for a2a traces? with the mock-agent? the mock-agent is going to be released with the new adk very soon.

@inference-gateway-maintainer

inference-gateway-maintainer Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Model: ollama_cloud/deepseek-v4-flash · View Job

Todos

  • Understand current branch state and existing A2A trace propagation code
  • Understand the mock-agent and ADK 0.22.0 release context
  • Create an A2A traces example with mock-agent
  • Run pre-commit checks and push

Pull Request

#909

✅ Infer Result: Success

Everything is clean and pushed. The work is complete - no further action needed.

Model: ollama_cloud/deepseek-v4-flash · Exit Code: 0 · Duration: 12m 16s

Tokens: 3,602,442 in · 9,220 out · 3,611,662 total (32 requests)

Tool calls: 46 total · 93% success rate

⚠️ 3 failed tool call(s)
  • Bash:
    exit status -1: �[32mtask: [precommit:run] pre-commit run --all-files
    �[0m[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
    … (truncated)
    
  • Edit:
    new_string must be different from old_string
    
  • Edit:
    old_string not found in file /home/runner/work/cli/cli/examples/a2a-traces/README.md
    
    … (truncated)
    

Triggered by edenreich · Infer Action

Create a focused example demonstrating W3C trace context propagation between the infer CLI and A2A agents via the mock-agent (ADK 0.22.0+).

The example shows: - How the CLI injects traceparent/tracestate/baggage headers into A2A HTTP requests - How to enable telemetry on the CLI (INFER_TELEMETRY_ENABLED) - How to view the distributed trace tree with 'infer traces' - Mock-agent OTel export configuration for ADK 0.22.0+
claude Bot added a commit to inference-gateway/mock-agent that referenced this pull request Jul 14, 2026
Add examples/opentelemetry/ — a self-contained stack (mock-agent with
telemetry enabled + OpenTelemetry Collector + Jaeger) for exercising
distributed tracing end-to-end, including the shared-collector scenario
with the infer CLI telemetry feature (inference-gateway/cli#909).

Telemetry stays off by default (the ADK owns that default); the example
enables it via the A2A_TELEMETRY_* env vars and exports OTLP traces to a
shared collector so the agent's a2a.request span joins the CLI's trace.

- examples/opentelemetry/docker-compose.yaml: agent + collector + jaeger,
  with opt-in cli/debugger profiles
- examples/opentelemetry/otel-collector-config.yaml: OTLP in, Jaeger + debug out
- examples/opentelemetry/README.md: how to run it and view traces
- README.md: Telemetry & Tracing section linking the example
- .adl-ignore: protect hand-authored examples/ from regeneration

Refs #51

Co-authored-by: Eden Reich <[email protected]>
edenreich added a commit to inference-gateway/mock-agent that referenced this pull request Jul 14, 2026
* feat(telemetry): add OpenTelemetry support via agent.yaml manifest

* docs(telemetry): add runnable OpenTelemetry collector example

Add examples/opentelemetry/ — a self-contained stack (mock-agent with
telemetry enabled + OpenTelemetry Collector + Jaeger) for exercising
distributed tracing end-to-end, including the shared-collector scenario
with the infer CLI telemetry feature (inference-gateway/cli#909).

Telemetry stays off by default (the ADK owns that default); the example
enables it via the A2A_TELEMETRY_* env vars and exports OTLP traces to a
shared collector so the agent's a2a.request span joins the CLI's trace.

- examples/opentelemetry/docker-compose.yaml: agent + collector + jaeger,
  with opt-in cli/debugger profiles
- examples/opentelemetry/otel-collector-config.yaml: OTLP in, Jaeger + debug out
- examples/opentelemetry/README.md: how to run it and view traces
- README.md: Telemetry & Tracing section linking the example
- .adl-ignore: protect hand-authored examples/ from regeneration

Refs #51

Co-authored-by: Eden Reich <[email protected]>

---------

Co-authored-by: inference-gateway-maintainer[bot] <246577062+inference-gateway-maintainer[bot]@users.noreply.github.com>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Eden Reich <[email protected]>
inference-gateway-releaser Bot added a commit to inference-gateway/mock-agent that referenced this pull request Jul 14, 2026
## [0.2.0](v0.1.11...v0.2.0) (2026-07-14)

### ✨ Features

* **telemetry:** add OpenTelemetry support via agent.yaml manifest ([#55](#55)) ([36db7e8](36db7e8)), references [inference-gateway/cli#909](inference-gateway/cli#909) [#51](#51)

### 🐛 Bug Fixes

* **flox:** pin go-task to ^3.48.0 and bump manifest schema to 1.13.0 ([#44](#44)) ([8c5c4ab](8c5c4ab))

### 👷 CI

* **claude:** change effort to max ([cf2aca2](cf2aca2))
* **claude:** remove system prompt - use default community maintained prompt ([0cfbcf7](0cfbcf7))
* **claude:** standardize workflow + task-based branch prefix ([8aee026](8aee026))
* **deps:** bump actions/checkout in the github-actions group ([#35](#35)) ([65b7fd8](65b7fd8))
* **deps:** Bump anthropics/claude-code-action in the github-actions group ([#30](#30)) ([b86d3c5](b86d3c5))
* **deps:** bump anthropics/claude-code-action in the github-actions group ([#32](#32)) ([4805f63](4805f63))
* **deps:** bump github.com/inference-gateway/sdk in the gomod group ([#31](#31)) ([03ccbd5](03ccbd5))
* **deps:** bump github.com/inference-gateway/sdk in the gomod group ([#36](#36)) ([1dbf416](1dbf416))
* **deps:** bump github.com/inference-gateway/sdk in the gomod group ([#37](#37)) ([4580301](4580301))
* **deps:** bump github.com/inference-gateway/sdk in the gomod group ([#50](#50)) ([90899f8](90899f8))
* **deps:** bump github.com/inference-gateway/sdk in the gomod group ([#53](#53)) ([455c984](455c984))
* **deps:** bump github.com/quic-go/quic-go from 0.59.0 to 0.59.1 ([#33](#33)) ([3a80b04](3a80b04))
* **deps:** bump golang.org/x/crypto from 0.51.0 to 0.52.0 ([#43](#43)) ([0fd1504](0fd1504))
* **deps:** bump golang.org/x/net from 0.51.0 to 0.55.0 ([#40](#40)) ([73833a7](73833a7))
* **deps:** bump the github-actions group with 2 updates ([#38](#38)) ([b2c3d2e](b2c3d2e))
* **deps:** bump the github-actions group with 2 updates ([#41](#41)) ([1b23d61](1b23d61))
* **deps:** bump the github-actions group with 6 updates ([#39](#39)) ([c023410](c023410))
* **deps:** bump the gomod group with 3 updates ([#42](#42)) ([c3eb2ef](c3eb2ef))
* **deps:** downgrade task version from 3.51.1 to 3.48.0 in workflows and manifest ([7bd813e](7bd813e))
* **release:** update semantic release and plugins to latest versions with local installation ([d13b918](d13b918))

### 🔧 Miscellaneous

* **deps:** bump ADL CLI to v0.46.0 ([#46](#46)) ([f30c770](f30c770))
* **deps:** bump ADL CLI to v0.46.5 ([#49](#49)) ([ba8e7c8](ba8e7c8))
* **deps:** bump ADL CLI to v0.47.1 ([#54](#54)) ([c61da04](c61da04))
* **deps:** bump ADL CLI v0.39.3 -> v0.40.0 ([#28](#28)) ([db16a9a](db16a9a))
* **deps:** bump ADL CLI v0.40.0 -> v0.43.2 ([#29](#29)) ([dd0fc67](dd0fc67))
* **deps:** bump ADL CLI v0.43.2 -> v0.44.0 ([#34](#34)) ([8d33102](8d33102))
* **deps:** bump ADL CLI v0.46.5 -> v0.47.0 ([#52](#52)) ([3fcf418](3fcf418))
* **deps:** bump docker/setup-qemu-action version v4.0.0 -> v4.1.0 ([0d3999d](0d3999d))
* **deps:** update Go version from 1.26.2 to 1.26.4 ([bde7a3e](bde7a3e))
* **flox:** add missing lock file changes ([86a8440](86a8440))
* **schema:** update adl schema to latest ([a063018](a063018))
* small fix ([56cee02](56cee02))
inference-gateway-maintainer Bot added a commit to inference-gateway/docs that referenced this pull request Jul 15, 2026
…eiver_address, a2a-traces example

Add documentation for the CLI distributed-tracing surface added in inference-gateway/cli#909:

- Document telemetry.receiver_address config key (INFER_TELEMETRY_RECEIVER_ADDRESS) with default loopback-only behavior and fixed-address usage for external collector fan-back

- Document the a2a-traces example with push/pull topology, W3C trace context propagation to A2A agents, and collector fan-back to the CLI receiver

- Document that ingested foreign spans are labeled name [service] from the producer's service.name resource attribute

- Link back to the source PR inference-gateway/cli#909
edenreich pushed a commit to inference-gateway/docs that referenced this pull request Jul 15, 2026
…eiver_address, a2a-traces example (#406)

Add documentation for the CLI distributed-tracing surface added in inference-gateway/cli#909:

- Document telemetry.receiver_address config key (INFER_TELEMETRY_RECEIVER_ADDRESS) with default loopback-only behavior and fixed-address usage for external collector fan-back

- Document the a2a-traces example with push/pull topology, W3C trace context propagation to A2A agents, and collector fan-back to the CLI receiver

- Document that ingested foreign spans are labeled name [service] from the producer's service.name resource attribute

- Link back to the source PR inference-gateway/cli#909

Co-authored-by: inference-gateway-maintainer[bot] <246577062+inference-gateway-maintainer[bot]@users.noreply.github.com>
@edenreich
edenreich merged commit d1c09da into main Jul 16, 2026
1 check passed
@edenreich
edenreich deleted the feat/trace-propagation branch July 16, 2026 09:25
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.147.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Jul 16, 2026
@edenreich edenreich moved this from In progress to Done in 2026 Jul 16, 2026
inference-gateway-releaser Bot added a commit to inference-gateway/docs that referenced this pull request Jul 18, 2026
## [0.9.2](0.9.1...0.9.2) (2026-07-18)

### 📚 Documentation

* add CLI telemetry documentation for traces, logs, and metrics ([#392](#392)) ([f8bfcdc](f8bfcdc))
* **adk:** align telemetry docs with A2A_TELEMETRY_ENABLE as single trace gate ([#403](#403)) ([fea405f](fea405f)), references [inference-gateway/adk#234](inference-gateway/adk#234)
* **adl-cli,adk:** document OTel service.name/service.version from ADL manifest metadata ([#408](#408)) ([be1b66e](be1b66e))
* **adl-cli:** move generated skills to .agents/skills layout ([#421](#421)) ([2e4e925](2e4e925))
* align ADK telemetry config with OpenTelemetry ([#400](#400)) ([aa0a862](aa0a862))
* **cli-channels:** document channels-manager OTLP telemetry setup ([#415](#415)) ([283ddff](283ddff))
* **cli,a2a:** document A2A agent liveness probes ([#425](#425)) ([5844ea9](5844ea9)), closes [#424](#424)
* **cli:** document distributed tracing - infer traces, telemetry.receiver_address, a2a-traces example ([#406](#406)) ([4fc24f5](4fc24f5)), references [inference-gateway/cli#909](inference-gateway/cli#909)
* document /tasks output panel and agent inherit_mock ([#388](#388)) ([7f3d72b](7f3d72b))
* document built-in skills and tmux skill ([#386](#386)) ([fc013ab](fc013ab))
* document extended spec.telemetry otel exporter fields ([#399](#399)) ([712f6de](712f6de))
* document infer traces command and /traces shortcut ([#393](#393)) ([b938a19](b938a19))
* document infer-action workflow for infer orchestrator ([#396](#396)) ([4e1d792](4e1d792))
* document W3C trace propagation and OTLP span ingestion ([#394](#394)) ([f26494c](f26494c))
* **llamacpp:** add llama.cpp provider documentation ([#417](#417)) ([356f9ac](356f9ac))
* note Go SDK retry cancellation preserves HTTP error ([#382](#382)) ([e39bcab](e39bcab))
* **observability:** document OTEL_METRICS_EXPORTER and Prometheus pull env vars ([#412](#412)) ([b450177](b450177)), closes [#409](#409)
* **operator:** add Orchestrator CRD telemetry reference ([#413](#413)) ([8210e06](8210e06))
* **rust-adk:** document A2A_OTEL_TRACES_EXPORTER trace gating ([#407](#407)) ([29c5f67](29c5f67))
* **sdks:** add llamacpp to supported providers list ([#422](#422)) ([ed2a466](ed2a466))
* **sdks:** document python responses api and zai provider ([#423](#423)) ([c5b608e](c5b608e))

### 🔧 Miscellaneous

* **deps-dev:** bump the bun group with 2 updates ([#384](#384)) ([fc813d8](fc813d8))
* **deps:** bump infer CLI v0.141.0 -> v0.147.1 ([#411](#411)) ([03b6342](03b6342))
* **release:** update GitHub App credentials to use RELEASER_APP_ID and RELEASER_APP_PRIVATE_KEY ([4275006](4275006))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

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

1 participant