feat(observability): propagate trace context to spawned subprocesses#27085
Open
jlguerreiro wants to merge 1 commit into
Open
feat(observability): propagate trace context to spawned subprocesses#27085jlguerreiro wants to merge 1 commit into
jlguerreiro wants to merge 1 commit into
Conversation
When opencode spawns a tool subprocess (shell tool, stdio MCP transports, LSP servers, etc.), inject the active OTel context as TRACEPARENT (and TRACESTATE when non-empty) per the OTel env-carrier spec. Subprocess instrumentation that follows the spec then chains into opencode's invocation trace instead of starting a disconnected root. Closes anomalyco#27031. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #27031
Type of change
What does this PR do?
When OpenCode spawns a tool subprocess (shell tool, stdio MCP transports, LSP servers, etc.), inject the active OTel context as
TRACEPARENT(andTRACESTATEwhen non-empty) per the OTel env-carrier spec. Subprocess instrumentation that follows the spec then chains into OpenCode's invocation trace instead of starting a disconnected root.How did you verify your code works?
Unit tests — added in
packages/core/test/effect/observability.test.tscovering: no-op without active span,TRACEPARENTinjection from a given context, sampled vs. unsampled flag encoding, invalid spancontext, stale
TRACEPARENToverwrite, default-arg fallback.End-to-end check
Ran opencode with OTel enabled, prompted it to spawn an OTel-instrumented child via the shell tool, and confirmed that the child's span sits on the same trace and lists OpenCode's
ShellTool.runas its parent. Thatparent_span_idmatch across process boundaries.Script used for the E2E check
Checklist