Skip to content

opentelemetry: Resample in Span::updateParent() - #48451

Open
dmcardle wants to merge 9 commits into
envoyproxy:mainfrom
dmcardle:otel-copy-parent-sample-bit
Open

dmcardle wants to merge 9 commits into
envoyproxy:mainfrom
dmcardle:otel-copy-parent-sample-bit

Conversation

@dmcardle

@dmcardle dmcardle commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

@repokitteh-read-only

Copy link
Copy Markdown

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #48451 was opened by dmcardle.

see: more, trace.

@dmcardle
dmcardle force-pushed the otel-copy-parent-sample-bit branch from 051e276 to 9ec76db Compare October 19, 2026 22:44
@dmcardle
dmcardle force-pushed the otel-copy-parent-sample-bit branch 3 times, most recently from a6a95a9 to 91aafe3 Compare October 21, 2026 20:29
@dmcardle
dmcardle force-pushed the otel-copy-parent-sample-bit branch 2 times, most recently from 7f15298 to 196819e Compare October 21, 2026 22:47
@dmcardle dmcardle changed the title opentelemetry: Copy the parent's sample bit in Span::updateParent() opentelemetry: Resample in Span::updateParent() Oct 21, 2026
@dmcardle
dmcardle force-pushed the otel-copy-parent-sample-bit branch 8 times, most recently from be53dd5 to 5ec0838 Compare October 24, 2026 00:09
@dmcardle
dmcardle marked this pull request as ready for review October 24, 2026 00:10
@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 @htuch
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #48451 was ready_for_review by dmcardle.

see: more, trace.

@dmcardle
dmcardle force-pushed the otel-copy-parent-sample-bit branch from 5ec0838 to 0c1cb2d Compare October 26, 2026 15:59
@dmcardle
dmcardle force-pushed the otel-copy-parent-sample-bit branch 2 times, most recently from b261ad5 to 78820ca 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 otel-copy-parent-sample-bit branch 2 times, most recently from 021d3d4 to 874a8fb Compare October 30, 2026 21:35
@dmcardle
dmcardle force-pushed the otel-copy-parent-sample-bit branch 4 times, most recently from 6f45541 to d20e2a6 Compare November 2, 2026 17:59
botengyao pushed a commit that referenced this pull request Nov 3, 2026
<!--
!!!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 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. #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]>
@dmcardle
dmcardle force-pushed the otel-copy-parent-sample-bit branch from d20e2a6 to 5ce21e7 Compare November 3, 2026 16:14
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]>
@dmcardle
dmcardle force-pushed the otel-copy-parent-sample-bit branch from 5ce21e7 to 672f6bb Compare November 24, 2026 17:09
@dmcardle
dmcardle force-pushed the otel-copy-parent-sample-bit branch from 672f6bb to fe867f3 Compare November 24, 2026 17:43
@dmcardle
dmcardle force-pushed the otel-copy-parent-sample-bit branch from c81543e to b14aa12 Compare November 24, 2026 21:03
}

ENVOY_LOG(debug, "Not resampling in updateParent");
setSampled(context->sampled());

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.

updateParent() can now turn sampling on for a request Envoy decided not to trace. Driver::startSpan() passes every span from Tracer::startSpan() through applyTracingDecision (#45830), which calls setSampled(false) when tracing_decision.traced is false. Neither branch here does that. Please apply Envoy's decision on both branches, for example with Tracing::TracerUtility::shouldTraceRequest(stream_info_), and fix the second block of UpdateParentResamplesWithoutSampler, which expects a NotTraceable span to become sampled.

setParentId(context->spanId());

// Resample now that we have the correct trace context.
if (resample_on_update_parent_ && parent_tracer_.sampler() != nullptr) {

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.

With a sampler configured and resample_on_update_parent unset, the sampler is skipped and line 116 overwrites its earlier decision with the parent's flag. Tracer::startSpan() with the same parent asks the sampler (line 478). If the aim is to mirror startSpan(), the sampler runs whenever one is configured and the field selects nothing. What is false meant to do when a sampler is configured? If the field stays, please add a test for a configured sampler with the field unset.

}
}

TEST_F(OpenTelemetryDriverTest, UpdateParentKeepsLocalDecisionWithoutSamplerByDefault) {

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.

nit: this test asserts the local decision is not kept. Maybe UpdateParentAdoptsParentDecisionWithoutSamplerByDefault. UpdateParentResamplesWithoutSampler above likewise does not resample.

OTelSpanKind span_kind);
OTelSpanKind span_kind, bool preserve_headers = false);

SamplerSharedPtr sampler() const { return sampler_; }

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.

nit: this copies the shared_ptr on every call, and updateParent() calls it twice. Return const SamplerSharedPtr&.

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]>

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants