Repository navigation
opentelemetry: Override Span::updateParent() - #48448
Conversation
775f162 to
ed983e6
Compare
|
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to |
7be0ef7 to
b9b1fd7
Compare
c721478 to
85d00fa
Compare
…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]>
eea6baf to
71f2b97
Compare
<!-- !!!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]>
71f2b97 to
2aa90df
Compare
2aa90df to
4e8dc08
Compare
…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]>
ce0f9e0 to
488c0c0
Compare
|
/retest |
|
@botengyao, PTAL! |
botengyao
left a comment
There was a problem hiding this comment.
thanks Dan for breaking this out! lgtm with 2 comments.
/wait
| } | ||
|
|
||
| void Span::updateParent(const Tracing::TraceContext& trace_context, bool preserve_headers) { | ||
| preserve_headers_ = preserve_headers; |
There was a problem hiding this comment.
A couple of issues here:
preserve_headers_is set here, but never checked inSpan::injectContext()in this PR (looks like that hunk stayed in mcp: Reparent active span based on body's traceparent #48038). Also we should only updatepreserve_headers_aftercontext.ok(), and propagate it to router child spans (spawn_upstream_span) while still allowing async client sidecalls (upstream.async_client_span_) to inject headers.- For
tracestate, if the span initially gottracestatefrom a different HTTPtraceparent, merging leaks state across traces. NaiveStrJoincan also produce duplicate keys (e.g.foo=2,foo=1), which violates W3Ctracestaterules (Tracing::isValidTraceState()). Should we just replace it withcontext->tracestate()(matchingTracer::startSpan()with a parent context)?
Proposed fix:
void Span::updateParent(const Tracing::TraceContext& trace_context, bool preserve_headers) {
SpanContextExtractor extractor(trace_context);
absl::StatusOr<SpanContext> context = extractor.extractSpanContext();
if (!context.ok()) {
ENVOY_LOG(debug, "Unable to extract span context in updateParent: {}", context.status());
return;
}
preserve_headers_ = preserve_headers;
setParentContextIsRemote(context->isRemote());
setTraceId(context->traceId());
setParentId(context->spanId());
setTracestate(context->tracestate());
}And in Span::injectContext() (plus propagating preserve_headers_ in spawnChild()):
void Span::injectContext(Tracing::TraceContext& trace_context,
const Tracing::UpstreamContext& upstream) {
if (preserve_headers_ && !upstream.async_client_span_) {
return;
}
...wdyt?
There was a problem hiding this comment.
preserve_headers
preserve_headers_is set here, but never checked inSpan::injectContext()in this PR (looks like that hunk stayed in mcp: Reparent active span based on body's traceparent #48038).
Done. Good catch.
Also we should only update
preserve_headers_aftercontext.ok(),
OK. The effect is that we'll leave the headers alone if we don't understand the trace context.
and propagate it to router child spans (
spawn_upstream_span)
I think propagating to child spans makes sense. I'm just trying to figure out whether it's possible for spawnChild() to run before updateParent(). If it runs before, then the child span's preserve_headers_ value would potentially become stale. WDYT @botengyao, is this a valid concern?
while still allowing async client sidecalls (
upstream.async_client_span_) to inject headers.
Done. Added a preserve_headers param to OpenTelemetry's Tracer::startSpan().
tracestate
- For
tracestate, if the span initially gottracestatefrom a different HTTPtraceparent, merging leaks state across traces. NaiveStrJoincan also produce duplicate keys (e.g.foo=2,foo=1), which violates W3Ctracestaterules (Tracing::isValidTraceState()). Should we just replace it withcontext->tracestate()(matchingTracer::startSpan()with a parent context)?>
You're right that the keys have to be unique. I'm new to tracing, and it turns out I misread the trace-context spec. Now I think I see where the uniqueness requirement comes in (section 3.3.1.4: "Only one entry per key is allowed because the entry represents that last position in the trace.").
I know @paul-r-gall had a concern about potentially clobbering the sampler-selected tracestate. It looks like we might already do that? First, we will use the tracestate from the sampler in callSampler() (I think the span is new and the tracestate should be empty). Then, in startSpan() we may overwrite the current tracestate with the given trace context. The sampler-selected value would be clobbered here, right? [Edit: I see that startSpan() only sets the tracestate when there's no sampler.]
I'll go ahead and replace the span's tracestate with the one from the MCP request body. I think this matches the current implementation — we definitely want traces based on the MCP request body to match traces based on the headers. WDYT @botengyao and @paul-r-gall?
488c0c0 to
e59aca6
Compare
|
Thanks for the review, @botengyao! |
e59aca6 to
9e952ae
Compare
Signed-off-by: dmcardle <[email protected]>
Signed-off-by: dmcardle <[email protected]>
6edc76d to
a0b46cd
Compare
Signed-off-by: dmcardle <[email protected]>
a0b46cd to
b5d48fd
Compare
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]>
Commit Message: opentelemetry: Override Span::updateParent()
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:
modefield to TraceContextPropagationConfig in mcp.proto #48249resample_on_update_parentto OpenTelemetryConfig #48450Risk 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:]