-
Notifications
You must be signed in to change notification settings - Fork 107
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
url encode baggage keys and values #233
Conversation
Codecov Report
@@ Coverage Diff @@
## main #233 +/- ##
==========================================
+ Coverage 34.79% 35.59% +0.80%
==========================================
Files 37 37
Lines 3052 3149 +97
==========================================
+ Hits 1062 1121 +59
- Misses 1990 2028 +38
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
Converting chardata baggage to binaries only in otel_propagator:text_map_inject/1
leaves us open to confusion if people mix binaries and chardata in their arguments to otel_baggage:set/1
and set/2
and then call get_all/0
. Are you up for converting in the set functions? Failing that, erroring with badarg
on chardata?
I'm blocked on waiting for Erlang 23.2.7 to install so I can continue testing, but next I'll be checking for the whitespace decoding.
otel_baggage:set(<<"key-1">>, <<"value=1">>), | ||
otel_baggage:set(<<"key-2">>, <<"value-2">>), |
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.
If we're still accepting UTF-8 chardata as arguments, perhaps we could reflect that in the tests?
otel_baggage:set(<<"key-1">>, <<"value=1">>), | |
otel_baggage:set(<<"key-2">>, <<"value-2">>), | |
%% We prefer UTF-8 binary keys and values... | |
otel_baggage:set(<<"key-1">>, <<"value=1">>), | |
%% ... but still support UTF-8 character lists: | |
otel_baggage:set("key-2", "value-2"), |
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.
Unfortunately the clean way of declaring the keys literally would be <<"key-1"/utf8>>
since otherwise byte values > 255 get truncated
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.
Yeah, the smiley face [128512] for example would need encoding… as much as I'd prefer to avoid crashing out, it's more straightforward to throw a bad match than stack up on “friendly” special case handling.
In case I'm missing your point, though, <<"😀"/utf8>>
would be a great example for people mining our tests for usage hints. I was surprised to see <<"😀">> == <<0>>
.
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.
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.
Fair enough. Next-best: either dropping chardata arguments, or quietly converting them to binary.
Whitespace strips OK, but we need to split off the opaque metadata from each value. Using the example from the spec: :otel_propagator.text_map_extract([{"baggage", "key1=value1;property1;property2, key2 = value2, key3=value3; propertyKey=propertyValue"}])
:otel_baggage.get_all()
# result:
%{
"key1" => "value1;property1;property2",
"key2" => "value2",
"key3" => "value3; propertyKey=propertyValue"
}
# expected:
%{
"key1" => "value1",
"key2" => "value2",
"key3" => "value3"
} The spec doesn't say we SHOULD preserve the metadata to pass it along late; let's just drop it? |
0dab7cd
to
9276fa5
Compare
decode_value(Value) -> | ||
percent_decode(string:trim(unicode:characters_to_binary(Value))). | ||
|
||
%% TODO: call `uri_string:percent_decode' and remove this when OTP-23 is |
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.
Should we deal with any licensing and copyright here?
871426e
to
da13b97
Compare
@garthk if we are going to parse out the metadata I don't see a reason to drop it. But this will mean the value will become a 2-tuple:
|
It'd make for some entertaining API choices. :) Least surprising there might be |
Right. I was thinkingi the same. Except instead of |
Oh, of course, because metadata is its own list of bare keys and key-value pairs. |
I've added support for metadata. I'd have made it a separate PR but realized this one still had open issues so added it on, hopefully aside from fixes this is it and I won't let it grow anymore :) |
?assertEqual(#{<<"key-1">> => {<<"value=1">>, []}, | ||
<<"key-2">> => {<<"value-2">>, [<<"metadata">>]}}, otel_baggage:get_all()), |
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.
Could we show the {<<"metadata_key">>,<<"metadata_value">>}
form, also?
%% TODO: should the whole baggage entry be dropped if metadata is bad? | ||
%% drop bad metadata (the `1'). |
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.
Drop the bad metadata value only, I think.
da1f036
to
8ce95b9
Compare
1 similar comment
b98d946
to
70d1ac4
Compare
3f23fb6
to
99d475d
Compare
0f8bee3
to
84615da
Compare
Fix for #224 and #225
This may not be completely ready yet but opening now for review.
Possible changes needed:
?
and;
should be percent encoded if that is the case so even if it is just part of the value it may need updates to act properly.)Baggage spec: https://w3c.github.io/baggage/