Skip to content
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

[api-baggage] fix encoding of space chars in baggage item value #5303

Conversation

lachmatt
Copy link
Contributor

@lachmatt lachmatt commented Feb 1, 2024

Fixes #5260

Changes

Fixes encoding of ' ' char in baggage item values when injecting baggage.
Spaces should be percent-encoded, instead of being converted to '+' character.

Note

Some characters not required to be percent-encoded by the W3C baggage specification are percent-encoded, which results in longer representation.
This might be important considering baggage limits.

Alternative:

Custom encoder, which escapes only characters required by the W3C baggage specification.
Draft in #5292

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@lachmatt lachmatt requested a review from a team February 1, 2024 12:20
Copy link

codecov bot commented Feb 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.58%. Comparing base (6250307) to head (8046eaa).
Report is 167 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5303      +/-   ##
==========================================
+ Coverage   83.38%   85.58%   +2.19%     
==========================================
  Files         297      289       -8     
  Lines       12531    12588      +57     
==========================================
+ Hits        10449    10773     +324     
+ Misses       2082     1815     -267     
Flag Coverage Δ
unittests ?
unittests-Solution-Experimental 85.56% <100.00%> (?)
unittests-Solution-Stable 85.49% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...metry.Api/Context/Propagation/BaggagePropagator.cs 85.48% <100.00%> (ø)

... and 63 files with indirect coverage changes

vishweshbankwar
vishweshbankwar previously approved these changes Feb 7, 2024
Copy link
Member

@vishweshbankwar vishweshbankwar left a comment

Choose a reason for hiding this comment

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

LGTM - requires changelog. @alanwest Could you take a look as well?

Copy link
Contributor

@Kielek Kielek left a comment

Choose a reason for hiding this comment

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

I would go with #5292, but this is also improvement.

@vishweshbankwar
Copy link
Member

vishweshbankwar commented Feb 7, 2024

@lachmatt I missed something earlier - I think this would cause an issue due to difference in versions. https://learn.microsoft.com/en-us/dotnet/api/system.uri.unescapedatastring?view=net-8.0#remarks

Consider a service using old sdk injecting baggage and receiving side service(incoming request) updates to this change. it would cause issues with space decoding.

Copy link
Contributor

This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or Pushing will instruct the bot to automatically remove the label. This bot runs once per day.

@github-actions github-actions bot added the Stale Issues and pull requests which have been flagged for closing due to inactivity label Feb 15, 2024
@github-actions github-actions bot removed the Stale Issues and pull requests which have been flagged for closing due to inactivity label Feb 20, 2024
@lachmatt
Copy link
Contributor Author

lachmatt commented Feb 23, 2024

@lachmatt I missed something earlier - I think this would cause an issue due to difference in versions. https://learn.microsoft.com/en-us/dotnet/api/system.uri.unescapedatastring?view=net-8.0#remarks

Consider a service using old sdk injecting baggage and receiving side service(incoming request) updates to this change. it would cause issues with space decoding.

@vishweshbankwar That's a valid concern, but I don't see a good solution for it.
On the one hand, you might have service using old sdk injecting baggage, where + actually encodes space, on the other there are other, spec-compliant implementations (e.g from other languages), where + encodes +.

@pellared
Copy link
Member

@lachmatt I missed something earlier - I think this would cause an issue due to difference in versions. https://learn.microsoft.com/en-us/dotnet/api/system.uri.unescapedatastring?view=net-8.0#remarks

Consider a service using old sdk injecting baggage and receiving side service(incoming request) updates to this change. it would cause issues with space decoding.

True. This is just another reason that this should be fixed. Other (compliant with the specification e.g. from other languages) implementations will encode + as +. It is not possible to have decoding that would support both the buggy encoding and spec-complaint encoding.

Copy link
Contributor

github-actions bot commented Mar 2, 2024

This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or Pushing will instruct the bot to automatically remove the label. This bot runs once per day.

@github-actions github-actions bot added the Stale Issues and pull requests which have been flagged for closing due to inactivity label Mar 2, 2024
@pellared
Copy link
Member

pellared commented Mar 6, 2024

@open-telemetry/dotnet-maintainers This bug makes the baggage propagation not working properly with other SDKs.

@github-actions github-actions bot removed the Stale Issues and pull requests which have been flagged for closing due to inactivity label Mar 7, 2024
@vishweshbankwar
Copy link
Member

@open-telemetry/dotnet-maintainers This bug makes the baggage propagation not working properly with other SDKs.

@lachmatt \ @pellared - Sorry for the delay on this. I do have some questions on the spec. I will reach out to you offline to get the clarification. Thanks for your patience.

Copy link
Contributor

This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or Pushing will instruct the bot to automatically remove the label. This bot runs once per day.

@github-actions github-actions bot added Stale Issues and pull requests which have been flagged for closing due to inactivity and removed Stale Issues and pull requests which have been flagged for closing due to inactivity labels Mar 21, 2024
@pellared
Copy link
Member

@open-telemetry/dotnet-approvers PTAL. We would like to have it fixed at least for 1.8.0.

Copy link
Member

@vishweshbankwar vishweshbankwar left a comment

Choose a reason for hiding this comment

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

LGTM

@pellared - Thanks for raising this w3c/baggage#134.

I have opened #5500 on our side to further expand the tests.

@CodeBlanch CodeBlanch added the pkg:OpenTelemetry.Api Issues related to OpenTelemetry.Api NuGet package label Apr 4, 2024
@CodeBlanch CodeBlanch changed the title [baggage] fix encoding of space chars in baggage item value [api-baggage] fix encoding of space chars in baggage item value Apr 4, 2024
@vishweshbankwar
Copy link
Member

@lachmatt - please add the changelog as well.

@CodeBlanch
Copy link
Member

@lachmatt - please add the changelog as well.

Yes I think we should mention this in CHANGELOG and note that is it potentially a breaking change.

@@ -2,6 +2,10 @@

## Unreleased

* **Breaking change:** Fix space character encoding for baggage item values
Copy link
Member

Choose a reason for hiding this comment

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

I suggest writing explicitly that space was encoded to + and now it is encoded to %20.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed in 50ed920

Copy link
Member

@CodeBlanch CodeBlanch left a comment

Choose a reason for hiding this comment

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

LGTM

@CodeBlanch CodeBlanch merged commit e46a446 into open-telemetry:main Apr 5, 2024
37 checks passed
@lachmatt lachmatt deleted the escapedatastring-when-injecting-baggage branch May 16, 2024 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:OpenTelemetry.Api Issues related to OpenTelemetry.Api NuGet package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[baggage] space encoding in baggage item value when injecting baggage
6 participants