Repository navigation
[API] Correct space and plus encoding in W3C Baggage #4765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7aa9708
d76ba2f
a93090a
37dd0b2
502f3bf
d9838a5
8412e51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,6 +104,7 @@ class OPENTELEMETRY_EXPORT Baggage | |
| } | ||
|
|
||
| // Returns shared_ptr of baggage after extracting key-value pairs from header | ||
| // Percent-decodes keys and values; a literal '+' remains a plus, not a space. | ||
| static nostd::shared_ptr<Baggage> FromHeader(nostd::string_view header) noexcept | ||
| { | ||
| if (header.size() > kMaxSize) | ||
|
|
@@ -165,6 +166,7 @@ class OPENTELEMETRY_EXPORT Baggage | |
| } | ||
|
|
||
| // Creates string from baggage object. | ||
| // Spaces are encoded as %20 and plus signs as %2B in keys and values. | ||
| std::string ToHeader() const noexcept | ||
| { | ||
| std::string header_s; | ||
|
|
@@ -320,10 +322,6 @@ class OPENTELEMETRY_EXPORT Baggage | |
| { | ||
| ret.push_back(c); | ||
| } | ||
| else if (c == ' ') | ||
| { | ||
| ret.push_back('+'); | ||
| } | ||
| else | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dropping the space branch changes the observable behavior of an inline function in
#4717 changed API behavior without a guard, so the exception may apply here. A mixed-version process emits either
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The decoder is now included in the proposed correction following #4765 (comment): That means the earlier compatibility argument needs qualification. Older C++ readers already understand The ABI question itself is still unresolved. Both changes alter inline definitions and observable behavior in Prepared by omp, an AI coding assistant running in the omp harness, on behalf of @hidingmyname. |
||
| { | ||
| ret.push_back('%'); | ||
|
|
@@ -335,7 +333,7 @@ class OPENTELEMETRY_EXPORT Baggage | |
| return ret; | ||
| } | ||
|
|
||
| // Uri decode key value pairs after extracting from header | ||
| // Percent-decode key-value pairs without applying form-style '+' decoding. | ||
| static std::string UrlDecode(nostd::string_view str, bool &err) | ||
| { | ||
| std::string ret; | ||
|
|
@@ -355,10 +353,6 @@ class OPENTELEMETRY_EXPORT Baggage | |
| common::detail::HexDigitValue(str[i + 2]))); | ||
| i += 2; | ||
| } | ||
| else if (str[i] == '+') | ||
| { | ||
| ret.push_back(' '); | ||
| } | ||
| // See https://www.w3.org/TR/baggage/#definition | ||
| else if ((str[i] >= '!') /* 21 */ | ||
| && (str[i] <= '~') /* 7E */ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think changing only the encode side makes things worse when C++ sits in the middle of a call chain.
Example: Service A (Go) -> Service B (C++) -> Service C (Go).
expr=1+1. Per the W3C spec,+is a normal character, so A sendsbaggage: expr=1+1.FromHeaderstill decodes+as a space, so B reads the value as1 1.ToHeaderturns the space back into+, so C receivesexpr=1+1. B misread the value itself, but C still gets the right one.ToHeadersends the space as%20, so C receivesexpr=1%201and reads it as1 1. The value is now wrong for every service after B, not just inside B.The way to avoid this is to also stop decoding
+as a space (line 354). The cost is that spaces sent by older C++ versions (as+) would be read as+by newer C++ services. But non-C++ receivers already read them that way today, so this only affects C++ to C++ calls between different versions and fixes the issue at once for newer versions.IMO the better trade off is to change both sides in a single PR/release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed: the encode-only change can turn B's existing misinterpretation into a persistent downstream corruption. The proposed update now changes both sides together: spaces are encoded as
%20, and a literal+is no longer decoded as a space.For your exact example, incoming
expr=1+1now remains1+1inside C++ B and is forwarded asexpr=1%2B1, so a conforming receiver C reads1+1. Incoming%20still becomes a space, and%2B/%2bstill becomes a plus. The same rules apply to keys and values; metadata remains in wire form.I changed the old extraction expectation that deliberately treated
bar+4asbar 4and added publicBaggagetests plus carrier/contextBaggagePropagatorextraction/injection coverage, including the forwarded header forexpr=1+1, round-trips, key/value plus signs and spaces, and unchanged metadata. The changelog and public docs now explain the real tradeoff: spaces emitted as+by older C++ senders become literal plus signs at newer C++ receivers. There is no way to distinguish those legacy spaces from intentional plus signs; non-C++ receivers already face that behavior. Older C++ receivers can read the newer sender's%20and%2B.This supersedes the earlier encode-only description. The separate inline-API ABI-policy decision in #4765 (comment) remains unresolved; I have not assumed an exception or introduced an arbitrary ABI guard. The paired correction is pushed in
8412e51. The exact public-propagator example fails before and passes after in C++14; 16 baggage + 7 propagator tests pass in each of ABI1/ABI2 configurations, with 22 more propagation tests passing. The changed C++ files pass clang-format 18.1.8. These direct tests do not settle the ABI-policy question or claim full SDK/CMake validation.Prepared by omp, an AI coding assistant running in the omp harness, on behalf of @hidingmyname.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@denizariyan
Agreed, my approval and the #4745 triage missed the forwarding case.
B decodes the header and calls
ToHeader(), built atd9838a56:Main and this PR each corrupt one of the two values for every service after B, and only changing both sides forwards both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The paired correction is already present in the current head,
8412e51e6dc721a9c7a7e20b91f220d07bba9295; the forwarding table above was built from the earlier encode-onlyd9838a56.The two requested edits are included:
UrlDecodeno longer has the form-style'+'branch, so a literal+is preserved.bar+4, notbar 4.With that head,
expr=1+1extracts as1+1and forwards asexpr=1%2B1;hello%20worldremains a space value and forwards with%20. The public forwarding regression failed ond9838a56and passed on8412e51, as recorded in the earlier reply. All 16 baggage and 7 baggage-propagator tests also passed in the current-head macOS job; that job's failure is in the SDK metrics multi-reader gauge timestamp assertions, not baggage.The inline-API ABI-policy question for @marcalff / @lalitb remains unresolved. This reply only identifies the implemented semantic correction; it does not assume an ABI exception or mark the review thread resolved.
Posted by the omp AI coding assistant in the omp harness on behalf of @hidingmyname.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks