Repository navigation
Conversation
|
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to |
b46a7aa to
9b55035
Compare
7977540 to
f560a81
Compare
dmcardle
left a comment
There was a problem hiding this comment.
I'm not quite sure about all the non-opentelemetry overrides of the new setter methods, but I figure this is enough to get some early feedback.
PTAL @paul-r-gall and @yanavlasov
| if (active_span != nullptr && rewrite_result != nullptr) { | ||
| active_span->setTraceId(rewrite_result->parsed_traceparent.traceId()); | ||
| active_span->setParentId(rewrite_result->original_parent_id); | ||
| active_span->setSampled(rewrite_result->parsed_traceparent.sampled()); |
There was a problem hiding this comment.
this is also a problem -- this allows a client to trigger sampled spans on every MCP request which can DoS/trigger expensive span exports for consumers of this filter.
Speaking purely from an otel perspective, this should (somehow) trigger a call into source/extensions/tracers/opentelemetry/tracer.cc callSampler method in order to respect the parent-based sampling policy on the configured tracer. I am not sure how this should work logistically.
There was a problem hiding this comment.
I'm considering adding another bool config knob that decides whether we copy the incoming sampling bit to the active span. Maybe this is worth doing in another PR. WDYT @paul-r-gall?
| ASSERT(buffer != nullptr); | ||
|
|
||
| absl::StatusOr<RewriteTraceContextResult> rewrite_result = | ||
| rewriteBodyWithNewTraceparent(*buffer, new_parent_id); |
There was a problem hiding this comment.
in cases where end_stream has not yet arrived (e.g. when shouldStopOnConfiguredAttributes is set), this buffer will not be the complete JSON body of the MCP request, and so the loadFromJsonNoThrow will fail. Additionally, the unconditional setContentLength below will cause a failure in such cases.
the "ideal" solution here is to track the offset of the tracing fields inside of McpJsonParser and do a rewrite directly into the buffer without re-parsing.
There was a problem hiding this comment.
in cases where end_stream has not yet arrived ...
I tried to deal with this by making McpFilter::decodeData return StopIterationAndBuffer when the new config knob is enabled and end_stream is false.
the "ideal" solution here is to track the offset of the tracing fields inside of McpJsonParser and do a rewrite directly into the buffer without re-parsing.
I couldn't figure out a way to get field offsets in McpFieldExtractor, via the ProtobufUtil::converter::ObjectWriter interface. I wound up re-parsing with Wuffs which is less than ideal. WDYT? Is it worth rewriting the McpFieldExtractor and friends to use Wuffs?
There was a problem hiding this comment.
@yanavlasov This thread is a little stale, but the question remains — should we try to avoid having two JSON parsers? The new code uses WuffsJsonCursor because it lets us extract token locations and thereby enables the quick-and-dirty rewrite algorithm in McpJsonParser::rewriteTraceContext(). (The naive alternative of fully parsing/serializing the request body opens a can of worms, such as numeric edge cases that don't round-trip.)
| */ | ||
| bool isRemote() const { return is_remote_; } | ||
|
|
||
| void setTraceId(std::string trace_id) { trace_id_ = std::move(trace_id); } |
There was a problem hiding this comment.
here and below: check for non-empty.
There was a problem hiding this comment.
@paul-r-gall Can you clarify? Do you think we should avoid overwriting trace_id_ with the empty string?
f560a81 to
ee756c5
Compare
228f623 to
c03d678
Compare
5c042af to
bc14dc6
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]>
bc14dc6 to
c7403cb
Compare
c7403cb to
2a9caa7
Compare
127bc78 to
c07fabe
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]>
c07fabe to
047f78d
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]>
b403f15 to
1f970e9
Compare
6e5673c to
7109a42
Compare
Signed-off-by: dmcardle <[email protected]>
Signed-off-by: dmcardle <[email protected]>
Signed-off-by: dmcardle <[email protected]>
Signed-off-by: dmcardle <[email protected]>
| // Stable-sorts the given `edits` by start position, then applies each edit to | ||
| // `body`. Rewrites without explicitly linearizing the buffer. Moves each | ||
| // `BufferEdit` in `edits`. | ||
| absl::Status rewriteBuffer(Buffer::Instance& body, absl::Span<BufferEdit> edits) { |
There was a problem hiding this comment.
Will be we doing rewriting in some other places? If so we should encapsulate this in a class.
There was a problem hiding this comment.
I don't anticipate that we'll be reusing this method, but I can think of one place I would have used this abstraction in the past. Maybe if we come up with one more use case, it'd be worth factoring into a common library?
| parsing_started_ = false; | ||
| } | ||
|
|
||
| absl::Status McpJsonParser::rewriteTraceContext(Buffer::Instance& body, |
There was a problem hiding this comment.
Do we always rewrite trace context in MCP if there are trace headers?
There was a problem hiding this comment.
We don't always rewrite trace context — the behavior is controlled by the config's TraceContextPropagationMode. For instance, if the mode is COPY, McpFilter will update the trace context headers based on the body, but it will not call rewriteTraceContext().
envoy/api/envoy/extensions/filters/http/mcp/v3/mcp.proto
Lines 79 to 93 in f36e4ce
…sertion Signed-off-by: dmcardle <[email protected]>
Commit Message: mcp: Reparent active span based on body's traceparent
This PR adds new behavior to
McpFiltercontrolled by thereparent_active_spanoption. When it's enabled, the filter will extract the body's traceparent, set attributes on the active span to place it under the incoming traceparent, and finally rewrite the request body and headers so the upstream will place its own spans under the active span.For reference, here is the full PR chain:
modefield to TraceContextPropagationConfig in mcp.proto #48249resample_on_update_parentto OpenTelemetryConfig #48450I added integration tests for
McpFilterand the opentelemetry tracer.Additional Description: 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:]