Skip to content

Properly encode baggage values and metadata#3740

Merged
jkwatson merged 7 commits into
open-telemetry:mainfrom
jkwatson:encode_baggage_values
Oct 14, 2021
Merged

Properly encode baggage values and metadata#3740
jkwatson merged 7 commits into
open-telemetry:mainfrom
jkwatson:encode_baggage_values

Conversation

@jkwatson

Copy link
Copy Markdown
Contributor

This PR does several things:

  1. Removes the strict validation of baggage values from the API.
  2. UTF-8/URL encodes/decodes baggage values and metadata in the W3CBaggagePropagator

Resolves #3442

@jkwatson jkwatson force-pushed the encode_baggage_values branch from 25e622a to 22de59e Compare October 13, 2021 19:50
@codecov

codecov Bot commented Oct 13, 2021

Copy link
Copy Markdown

Codecov Report

Merging #3740 (cf3d8cd) into main (39fb333) will increase coverage by 0.00%.
The diff coverage is 85.06%.

Impacted file tree graph

@@            Coverage Diff             @@
##               main    #3740    +/-   ##
==========================================
  Coverage     89.24%   89.24%            
- Complexity     3839     3873    +34     
==========================================
  Files           462      463     +1     
  Lines         11969    12109   +140     
  Branches       1163     1188    +25     
==========================================
+ Hits          10682    10807   +125     
- Misses          905      910     +5     
- Partials        382      392    +10     
Impacted Files Coverage Δ
...emetry/api/baggage/propagation/PercentEscaper.java 84.21% <84.21%> (ø)
.../opentelemetry/api/baggage/propagation/Parser.java 95.58% <87.50%> (-2.83%) ⬇️
...io/opentelemetry/api/baggage/ImmutableBaggage.java 100.00% <100.00%> (ø)
.../api/baggage/propagation/W3CBaggagePropagator.java 90.00% <100.00%> (+0.52%) ⬆️
...ntelemetry/sdk/extension/resources/OsResource.java 90.69% <0.00%> (+4.65%) ⬆️
...metry/sdk/extension/resources/ProcessResource.java 87.50% <0.00%> (+6.25%) ⬆️
...elemetry/sdk/extension/resources/HostResource.java 92.30% <0.00%> (+15.38%) ⬆️
...dk/extension/resources/ProcessRuntimeResource.java 100.00% <0.00%> (+16.66%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 39fb333...cf3d8cd. Read the comment docs.

*/
private static boolean isValueValid(String value) {
return value != null && StringUtils.isPrintableString(value);
return value != null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think removing the isPrintableString check in this class and filtering in the propagator is more consistent with the specs. But can be another PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the filtering is actually something that is even needed, given the encoding requirements. The otel spec doesn't mention anything about filtering, and I suspect that the W3C spec is just defining the wire format, not the input requirements. So, in the wire format, you URL-encode to make sure that you aren't using any non-ascii, delimiter characters, but the inputs can be whatever you want. At least, I think that's what's intended, even if it's quite poorly worded in the W3C spec.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or were you thinking about the key validation? That's another bit that I wish was better understood.

import org.junit.runner.RunWith;

class PercentEscaperFuzzTest {
@RunWith(JQF.class)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if RunWith is needed given the manual driving. No big deal

@anuraaga anuraaga Oct 14, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way if this feels too hacky, maybe can use easy-random + @RepeatedTest like I used for the random span stuff. It's pretty trivial to get a random string. Don't know if Fuzz does anything cool besides random though.

https://github.com/j-easy/easy-random
https://github.com/j-easy/easy-random/blob/master/easy-random-core/src/main/java/org/jeasy/random/randomizers/text/StringRandomizer.java

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked and @RunWith is needed. JQF does have some other interesting features that we could start leveraging in the future, but agreed that maybe we could use something else. In another PR. :)

@jkwatson jkwatson merged commit 69d26c1 into open-telemetry:main Oct 14, 2021
@jkwatson jkwatson deleted the encode_baggage_values branch October 14, 2021 15:10
This was referenced Dec 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Class: W3CBaggagePropagator should follow Open-Telemetry specification.

2 participants