Skip to content

envoy/tracing: Add method Envoy::Tracing::Span::updateParent() - #48250

Merged
botengyao merged 1 commit into
envoyproxy:mainfrom
dmcardle:span-updateparent-method
Nov 3, 2026
Merged

botengyao merged 1 commit into
envoyproxy:mainfrom
dmcardle:span-updateparent-method

Conversation

@dmcardle

@dmcardle dmcardle commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Commit Message:
Additional Description: This change supports #48038

This PR was created with help from generative AI (Gemini). I fully understand the code.

For reference, here is the full PR chain:

  1. api: Add mode field to TraceContextPropagationConfig in mcp.proto #48249
  2. envoy/tracing: Add method Envoy::Tracing::Span::updateParent() #48250
  3. opentelemetry: Add traceparent parse/serialize methods to SpanContextExtractor #48449
  4. opentelemetry: Override Span::updateParent() #48448
  5. opentelemetry: Move traceparent size constants into common lib #48516
  6. mcp: Reparent active span based on body's traceparent #48038
  7. opentelemetry: Add bool field resample_on_update_parent to OpenTelemetryConfig #48450
  8. opentelemetry: Resample in Span::updateParent() #48451

Risk Level:
Testing:
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]

@dmcardle

Copy link
Copy Markdown
Contributor Author

@paul-r-gall PTAL

@dmcardle
dmcardle force-pushed the span-updateparent-method branch 3 times, most recently from 245e9a8 to 781ff87 Compare October 13, 2026 19:46
@repokitteh-read-only

Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @mattklein123
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #48250 was synchronize by dmcardle.

see: more, trace.

@mattklein123 mattklein123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry but I'm a little lost on the purpose of this. If you enable tracing why wouldn't this always be the behavior? Wouldn't the default be to just proxy through without creating a parent span and this is what you get when you enable tracing?

/wait-any

@dmcardle

Copy link
Copy Markdown
Contributor Author

Sorry but I'm a little lost on the purpose of this. If you enable tracing why wouldn't this always be the behavior? Wouldn't the default be to just proxy through without creating a parent span and this is what you get when you enable tracing?

Hey @mattklein123, sorry for the delay.

For context, we already have a "passthrough" mode of MCP trace context propagation, where McpFilter just copies the request body's trace context into the headers. This mode is enabled when the propagate_trace_context field is present:

TraceContextPropagationConfig propagate_trace_context = 6;

Simple passthrough is fine when Envoy isn't going to generate a span, and it's necessary so the trace doesn't end at Envoy — after all, we want the upstream's spans to be hooked up to the request's trace context.

However, when we want Envoy to generate a span, simple passthrough is not sufficient. MCP puts the traceparent in the body rather than headers, so by the time McpFilter processes the MCP request body, Envoy has already created a span without knowledge of the body's trace context!

The workaround implemented by this stack of CLs is to mutate the active span, post-hoc, such that it's a child span of the body's traceparent. It also becomes necessary to rewrite the request body so the upstream's spans descend from the active span. This new behavior will be controlled by the boolean reparent_active_span field added by PR #48249.

I hope that makes sense, and please let me know if you have more questions. CC @paul-r-gall.

@dmcardle
dmcardle force-pushed the span-updateparent-method branch from 1e2e94c to bbb3a00 Compare October 21, 2026 17:53
@dmcardle

Copy link
Copy Markdown
Contributor Author

Simple passthrough is fine when Envoy isn't going to generate a span, and it's necessary so the trace doesn't end at Envoy — after all, we want the upstream's spans to be hooked up to the request's trace context.

Correction: the simple passthrough mode is currently broken when the OpenTelemetry tracer is also configured. I believe the issue is that injectContext() is called with the in-memory span. @paul-r-gall, please clarify if I didn't get that right.

// Set the traceparent in the trace_context.
traceParentHeader().setRefKey(trace_context, traceparent_header_value);
// Also set the tracestate.
traceStateHeader().setRefKey(trace_context, span_.trace_state());

mattklein123
mattklein123 previously approved these changes Oct 23, 2026

@mattklein123 mattklein123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK thanks this makes sense. I didn't understand the trace in body part.

@dmcardle
dmcardle force-pushed the span-updateparent-method branch from e5c04dd to 78ff718 Compare October 23, 2026 22:30
@dmcardle
dmcardle force-pushed the span-updateparent-method branch 4 times, most recently from 60aec91 to d8bf297 Compare October 27, 2026 21:16
* Reparent this span based on the given trace context.
*/
virtual void updateParent([[maybe_unused]] const TraceContext& context,
[[maybe_unused]] bool preserve_headers) {}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@paul-r-gall, @mattklein123, @botengyao: Any opinion this bool preserve_headers parameter?

I need some way to prevent the OpenTelemetry Span::injectContext() from overwriting headers when the McpFilter's trace context propagation mode is COPY or COPY_AND_REPARENT_SPAN. (We only want to rewrite the body/headers when the mode is REWRITE_AND_REPARENT_SPAN.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

SGTM

@dmcardle
dmcardle force-pushed the span-updateparent-method branch from d8bf297 to 88043f5 Compare October 28, 2026 14:06
botengyao pushed a commit that referenced this pull request Oct 29, 2026
…48249)

<!--
!!!ATTENTION!!!

If you are fixing **any** crash or **any** potential security issue,
**do not
open a pull request**.

Instead, please
[open a GitHub Security
Advisory](https://github.com/envoyproxy/envoy/security/advisories/new)
(preferred). Alternatively, you may email
[email protected].

Thank you in advance for helping to keep Envoy secure.

!!!ATTENTION!!!

For an explanation of how to fill out the fields, please see the
relevant section
in
[PULL_REQUESTS.md](https://github.com/envoyproxy/envoy/blob/main/PULL_REQUESTS.md)

!!!ATTENTION!!!

Please check the [use of generative AI
policy](https://github.com/envoyproxy/envoy/blob/main/CONTRIBUTING.md?plain=1#L41).

You may use generative AI only if you fully understand the code. You
need to disclose
this usage in the PR description to ensure transparency.
-->

Commit Message:
Additional Description:

This is the first PR in a chain, with the high-level goal of getting
McpFilter to reparent the active span based on the request body's trace
context.

For reference, here is the full PR chain:

1. #48249
1. #48250
1. #48449
1. #48448
1. #48516
1. #48038
1. #48450
1. #48451

This PR was created with help from generative AI (Gemini). I fully
understand the code.

Risk Level:
Testing:
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional [API
Considerations](https://github.com/envoyproxy/envoy/blob/main/api/review_checklist.md):]

Signed-off-by: dmcardle <[email protected]>
@dmcardle
dmcardle force-pushed the span-updateparent-method branch 2 times, most recently from 0879181 to 5c87940 Compare October 30, 2026 21:35
@dmcardle
dmcardle force-pushed the span-updateparent-method branch from 5c87940 to a3a3157 Compare November 2, 2026 15:34
@dmcardle

dmcardle commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@dmcardle

dmcardle commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

@botengyao or @paul-r-gall, please merge when you get a chance :)

@botengyao
botengyao merged commit 413bae5 into envoyproxy:main Nov 3, 2026
27 checks passed
botengyao pushed a commit that referenced this pull request Nov 19, 2026
…Extractor (#48449)

<!--
!!!ATTENTION!!!

If you are fixing **any** crash or **any** potential security issue,
**do not
open a pull request**.

Instead, please
[open a GitHub Security
Advisory](https://github.com/envoyproxy/envoy/security/advisories/new)
(preferred). Alternatively, you may email
[email protected].

Thank you in advance for helping to keep Envoy secure.

!!!ATTENTION!!!

For an explanation of how to fill out the fields, please see the
relevant section
in
[PULL_REQUESTS.md](https://github.com/envoyproxy/envoy/blob/main/PULL_REQUESTS.md)

!!!ATTENTION!!!

Please check the [use of generative AI
policy](https://github.com/envoyproxy/envoy/blob/main/CONTRIBUTING.md?plain=1#L41).

You may use generative AI only if you fully understand the code. You
need to disclose
this usage in the PR description to ensure transparency.
-->

Commit Message: opentelemetry: Add traceparent parse/serialize methods
to SpanContextExtractor

This new override will be used by McpFilter in PR #48038.

Additional Description: This PR was created with help from generative AI
(Gemini). I fully understand the code.

For reference, here is the full PR chain:

1. #48249
1. #48250
1. #48449
1. #48448
1. #48516
1. #48038
1. #48450
1. #48451

Risk Level:
Testing:
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional [API
Considerations](https://github.com/envoyproxy/envoy/blob/main/api/review_checklist.md):]

Signed-off-by: dmcardle <[email protected]>
yanavlasov pushed a commit that referenced this pull request Dec 1, 2026
This new override will be used by McpFilter in PR #48038.

Additional Description: This PR was created with help from generative AI
(Gemini). I fully understand the code.

For reference, here is the full PR chain:

1. #48249
1. #48250
1. #48449
1. #48448
1. #48516
1. #48038
1. #48450
1. #48451

Risk Level:
Testing:
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional [API
Considerations](https://github.com/envoyproxy/envoy/blob/main/api/review_checklist.md):]

---------

Signed-off-by: dmcardle <[email protected]>
yanavlasov pushed a commit that referenced this pull request Dec 2, 2026
This commit deduplicates constants related to W3C traceparent into
source/common/tracing/tracing_validation.h.

Additional Description:

This PR was created with help from generative AI (Gemini). I fully
understand the code.

For reference, here is the full PR chain:

1. #48249
1. #48250
1. #48449
1. #48448
1. #48516
1. #48038
1. #48450
1. #48451

Risk Level:
Testing:
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional [API
Considerations](https://github.com/envoyproxy/envoy/blob/main/api/review_checklist.md):]

Signed-off-by: dmcardle <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants