Skip to content

Apply percent decoding to resource attributes list - #4460

Open
WyshalZyren wants to merge 7 commits into
open-telemetry:mainfrom
WyshalZyren:fix-resource-attributes-percent-decode
Open

Apply percent decoding to resource attributes list#4460
WyshalZyren wants to merge 7 commits into
open-telemetry:mainfrom
WyshalZyren:fix-resource-attributes-percent-decode

Conversation

@WyshalZyren

Copy link
Copy Markdown

This updates resource.attributes_list handling to percent-decode values before storing them.

Changes include:

  • extracting PercentDecode into a reusable resource detail utility
  • using it in SdkBuilder::SetResource
  • keeping malformed percent sequences unchanged
  • adding direct decoder tests
  • adding resource.attributes_list parsing tests

Fixes #4456

@WyshalZyren
WyshalZyren requested a review from a team as a code owner August 20, 2026 06:01
@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 20, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: WyshalZyren / name: Wyshal Zyren (f62d624)

@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.23810% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.64%. Comparing base (b603742) to head (4b71ae9).
⚠️ Report is 1 commits behind head on main.

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

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4460      +/-   ##
==========================================
+ Coverage   82.62%   82.64%   +0.02%     
==========================================
  Files         512      513       +1     
  Lines       20138    20139       +1     
==========================================
+ Hits        16637    16641       +4     
+ Misses       3501     3498       -3     
Files with missing lines Coverage Δ
sdk/src/configuration/sdk_builder.cc 61.23% <100.00%> (+0.13%) ⬆️
sdk/src/resource/resource_detector.cc 100.00% <100.00%> (+2.39%) ⬆️
sdk/src/resource/detail/percent_decode.cc 94.45% <94.45%> (ø)

... 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.

@dbarker dbarker 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.

Thanks for the PR! Please see some minor feedback below. Once CI is passing I will approve.

Comment thread sdk/src/configuration/sdk_builder.cc Outdated
#include "opentelemetry/version.h"
#include "src/common/wildcard_match.h"

#include "../resource/detail/percent_decode.h"

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.

can this be src/resource/detail/percent_decode.h?

opentelemetry::common::AttributeValue wrapped_attribute_value(decoded_value);
list_attributes.SetAttribute(attribute_key, wrapped_attribute_value);
}
else

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.

if attribute_valid may still be false please keep this warning.

if (attribute_valid)
{
opentelemetry::common::AttributeValue wrapped_attribute_value(attribute_value);
std::string decoded_value = opentelemetry::sdk::resource::detail::PercentDecode(

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.

SetResource now calls PercentDecode, which is a non-inline symbol defined in the resource library, so configuration_core has a direct dependency on //sdk/src/resource for the first time.

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.

configuration_core has a dependency on sdk/src/resource due to ConfiguredSdk and SdkBuilder instantiating a resource object. The dependency is being fulfilled transitively from the SDK signal libraries (trace, metrics, and logs) currently. Setting an explicit dependency on resource is better.

@@ -2552,13 +2554,12 @@ void SdkBuilder::SetResource(
{
if (attribute_valid)

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.

Same as #4460 (comment), attribute_valid is still reachable, so removing the else drops a real diagnostic.

namespace detail
{

std::string PercentDecode(const std::string &value);

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.

Could you restore the contract on the declaration as comment?

Comment thread sdk/src/resource/resource_detector.cc Outdated
#include "opentelemetry/sdk/resource/resource_detector.h"
#include "opentelemetry/nostd/variant.h"

#include "detail/percent_decode.h"

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.

Same class as the other note on sdk_builder.cc. This is a subdirectory-relative include that bypasses the target's include_prefix.

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.

[CONFIGURATION] Apply percent decode to resource.attributes_list

3 participants