Skip to content

fix(ai): preserve explicit traceparent in HTTP requests - #61386

Open
siglp wants to merge 2 commits into
anomalyco:devfrom
siglp:fix/traceparent-propagation
Open

siglp wants to merge 2 commits into
anomalyco:devfrom
siglp:fix/traceparent-propagation

Conversation

@siglp

@siglp siglp commented Nov 3, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #49038

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Effect's HTTP client overwrites an existing traceparent header with its own trace context and may also add a B3 header from a different trace. This breaks trace correlation when a plugin injects its own trace context through request middleware.

The fix disables Effect's automatic trace propagation for requests that already contain a traceparent header. Requests without an explicit traceparent continue using the default behavior.

How did you verify your code works?

Built OpenCode locally and tested the complete tracing setup with:

  • OpenCode 2.2.4
  • AgentGateway 1.6.0
  • Langfuse 4.71.0
  • Modified Langfuse OpenCode observability plugin

Verified trace context propagation through OpenCode, AgentGateway and Langfuse.

Also added an integration test using a local HTTP server to verify the actual outgoing headers, including middleware-injected headers.

Full packages/ai test suite: 2,035 passed, 28 skipped, 0 failed.

All 35 pre-push checks passed.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix works. I ran the new test against the base branch: it fails there because Effect replaces the explicit traceparent with its own. With this change, test/executor.test.ts passes and typecheck:tsc is clean. I also checked Effect 4.1.0's client: the propagation setting is read inside the per-request effect that HttpClient.transform wraps, and header names are lowercased. So the check sees headers added by middleware, and turning propagation off applies to that request only.

Public API is unchanged. The only change in behaviour: a request that already has a traceparent no longer gets Effect's traceparent or b3 headers.

One request: the new test is large for a 9-line fix. Please cut it to the core cases (see inline comment).

Comment thread packages/ai/test/executor.test.ts Resolved

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My earlier request is addressed: the test is now cut down to the core cases (an explicit traceparent set directly, one set by middleware, both without b3, and normal propagation when there is none). It still fails on the base branch and passes with this change, and typecheck:tsc is clean. The fix itself is unchanged and the public API is unchanged. Nothing else to raise.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This push is a rebase onto newer dev; the fix and test are unchanged. On the rebased code, test/executor.test.ts passes and typecheck:tsc is clean. The public API is unchanged. Nothing new to raise.

@siglp
siglp force-pushed the fix/traceparent-propagation branch from 4619067 to 7b91415 Compare November 4, 2026 13:40

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This push is another rebase onto newer dev; the fix and test are unchanged. On the rebased code, test/executor.test.ts passes and typecheck:tsc is clean. The public API is unchanged. Nothing new to raise.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This push merges dev into the branch; the fix and test are unchanged. On the merged code, test/executor.test.ts passes and typecheck:tsc is clean. The public API is unchanged. Nothing new to raise.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This push merges dev into the branch again; the fix and test are unchanged. On the merged code, test/executor.test.ts passes and typecheck:tsc is clean. The public API is unchanged. Nothing new to raise.

@siglp
siglp force-pushed the fix/traceparent-propagation branch from eb1f035 to 79ee64c Compare November 6, 2026 08:49

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This push rebases the branch onto latest dev; the fix and test are unchanged. On the rebased code, test/executor.test.ts passes and typecheck:tsc is clean. The public API is unchanged. Nothing new to raise.

@siglp
siglp force-pushed the fix/traceparent-propagation branch from 79ee64c to d1312ce Compare November 8, 2026 09:38

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This push rebases the branch onto latest dev again; the fix and test are unchanged. On the rebased code, test/executor.test.ts passes and typecheck:tsc is clean. The public API is unchanged. Nothing new to raise.

@siglp
siglp force-pushed the fix/traceparent-propagation branch from d1312ce to 5879ac0 Compare November 8, 2026 13:39

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This push rebases the branch onto latest dev again; the fix and test are unchanged. On the rebased code, test/executor.test.ts passes and typecheck:tsc is clean. The public API is unchanged. Nothing new to raise.

@siglp
siglp force-pushed the fix/traceparent-propagation branch from 5879ac0 to ce9f381 Compare November 9, 2026 16:06

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This push rebases the branch onto latest dev again; the fix and test are unchanged. On the rebased code, test/executor.test.ts passes and typecheck:tsc is clean. The public API is unchanged. Nothing new to raise.

@siglp
siglp force-pushed the fix/traceparent-propagation branch from ce9f381 to 00e8b97 Compare November 10, 2026 10:27

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This push rebases the branch onto latest dev again; the fix and test are unchanged. On the rebased code, test/executor.test.ts passes and typecheck:tsc is clean. The public API is unchanged. Nothing new to raise.

@siglp
siglp force-pushed the fix/traceparent-propagation branch from 00e8b97 to c3b6ba3 Compare November 11, 2026 08:16

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This push rebases the branch onto latest dev again; the fix and test are unchanged. On the rebased code, test/executor.test.ts passes and typecheck:tsc is clean. The public API is unchanged. Nothing new to raise.

@siglp
siglp force-pushed the fix/traceparent-propagation branch from c3b6ba3 to af374eb Compare November 13, 2026 05:40

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This push rebases the branch onto latest dev again; the fix and test are unchanged. On the rebased code, test/executor.test.ts passes and typecheck:tsc is clean. The public API is unchanged. Nothing new to raise.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This push rebases the branch onto latest dev again; the fix and test are unchanged. On the rebased code, test/executor.test.ts passes and typecheck:tsc is clean. The public API is unchanged. Nothing new to raise.

@siglp
siglp force-pushed the fix/traceparent-propagation branch from 7561cc2 to 8d49719 Compare November 13, 2026 11:40

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This push rebases the branch onto latest dev again; the fix and test are unchanged. On the rebased code, test/executor.test.ts passes and typecheck:tsc is clean. The public API is unchanged. Nothing new to raise.

@siglp
siglp force-pushed the fix/traceparent-propagation branch from 8d49719 to 7b07e75 Compare November 14, 2026 01:06

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This push rebases the branch onto latest dev again; the fix and test are unchanged. On the rebased code, test/executor.test.ts passes and typecheck:tsc is clean. The public API is unchanged. Nothing new to raise.

This branch has not been deployed

No deployments
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.

[FEATURE]: propagate W3C traceparent on outbound LLM HTTP requests

1 participant