Skip to content

[SDK] Percent-decode values from OTEL_RESOURCE_ATTRIBUTES - #4364

Merged
marcalff merged 11 commits into
open-telemetry:mainfrom
om7057:sdk/resource-attributes-percent-decode
Aug 7, 2026
Merged

marcalff merged 11 commits into
open-telemetry:mainfrom
om7057:sdk/resource-attributes-percent-decode

Conversation

@om7057

@om7057 om7057 commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #1536.

The OpenTelemetry resource specification now requires values from OTEL_RESOURCE_ATTRIBUTES to be decoded using the W3C Baggage value grammar. While looking into this, I noticed that OTELResourceDetector::Detect() was parsing the attributes but storing values exactly as they appeared in the environment.

For example:

OTEL_RESOURCE_ATTRIBUTES="key=hello%20world"

was producing the value hello%20world instead of hello world.

This PR adds a small percent-decoding helper in sdk/src/resource/resource_detector.cc and applies it when parsing attribute values.

Malformed escape sequences are preserved rather than causing the attribute to be rejected, which matches the existing parser behavior of being permissive instead of validating attribute syntax.

The change is intentionally scoped to value decoding only. Parsing, trimming, and attribute key handling remain unchanged.

Testing

Added tests covering:

  • Common percent-encoded values (%20, %2C, %25).
  • Malformed escape sequences (such as a trailing % or invalid hex digits).
  • Existing OTELResourceDetector behavior to ensure there are no regressions.

The full resource_test suite passes locally.

The resource spec was updated to require decoding OTEL_RESOURCE_ATTRIBUTES
values per the W3C Baggage value grammar, but OTELResourceDetector::Detect()
stored the raw substring after '=' verbatim. A value like
"key=hello%20world" therefore became the literal string "hello%20world"
instead of "hello world".

Adds a local percent-decode helper scoped to resource_detector.cc; a
malformed escape sequence is left in the value as-is rather than dropping
the attribute, consistent with this parser never validating attribute
syntax elsewhere.

Fixes open-telemetry#1536
@om7057
om7057 requested a review from a team as a code owner August 5, 2026 18:27
@codecov

codecov Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 81.78%. Comparing base (5cfda3c) to head (5d2c5fc).

Files with missing lines Patch % Lines
sdk/src/resource/resource_detector.cc 94.74% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4364      +/-   ##
==========================================
+ Coverage   81.77%   81.78%   +0.01%     
==========================================
  Files         493      493              
  Lines       19456    19474      +18     
==========================================
+ Hits        15909    15924      +15     
- Misses       3547     3550       +3     
Files with missing lines Coverage Δ
sdk/src/resource/resource_detector.cc 97.62% <94.74%> (-2.38%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread sdk/src/resource/resource_detector.cc Resolved
om7057 added 2 commits August 6, 2026 08:04
Per marcalff's review comment, avoids re-evaluating and re-casting the
same byte twice when checking and decoding a percent-escape.
@om7057

om7057 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

@marcalff addressed the twice-happening cast; please check once.

@marcalff marcalff left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks for the fix.

@marcalff

marcalff commented Aug 7, 2026

Copy link
Copy Markdown
Member

@om7057

Please do not push new commit to re trigger a failed build.
Maintainers can restart failed builds in CI if necessary.

Also, no need to merge from main every time main changes.

@om7057

om7057 commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor Author

@om7057

Please do not push new commit to re trigger a failed build. Maintainers can restart failed builds in CI if necessary.

Also, no need to merge from main every time main changes.

@marcalff Understood. I was just trying to make sure that the PR remains in a mergeable state; I will avoid repeated merges moving forward.

@marcalff

marcalff commented Aug 7, 2026 •

Copy link
Copy Markdown
Member

Now that #4376 got in, it's your turn.

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.

Decode values from OTEL_RESOURCE_ATTRIBUTES

2 participants