Skip to content

sdk: percent-decode OTEL_RESOURCE_ATTRIBUTES keys as well as values - #5989

Open
WendeelMarinho wants to merge 2 commits into
open-telemetry:mainfrom
WendeelMarinho:fix/resource-attributes-decode-keys
Open

WendeelMarinho wants to merge 2 commits into
open-telemetry:mainfrom
WendeelMarinho:fix/resource-attributes-decode-keys

Conversation

@WendeelMarinho

Copy link
Copy Markdown

The resource SDK spec says "The , and = characters in keys and values MUST be percent encoded", but OTELResourceDetector only decodes the value, so my%2Ckey=v yields the key my%2Ckey. This decodes the key the same way (#2847 did it for values).

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I am a human and not a bot
  • I have run tox -e precommit
  • I have run the relevant tests and linting tox environments

@WendeelMarinho
WendeelMarinho requested a review from a team as a code owner December 1, 2026 15:33
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on maintainers · refreshed 2026-12-02 15:56 UTC

Merge when ready.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with the author? Comment /dashboard route:author to route it back.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

@WendeelMarinho
WendeelMarinho force-pushed the fix/resource-attributes-decode-keys branch from aee7e22 to affa360 Compare December 1, 2026 15:34
@knowprasad

Copy link
Copy Markdown
Contributor

I reviewed the changes in opentelemetry-sdk/src/opentelemetry/sdk/resources/init.py, opentelemetry-sdk/tests/resources/test_resources.py, and .changelog/5989.fixed.

The fix cleanly resolves the specification gap in OTELResourceDetector.detect().

A few specific observations from inspecting the implementation and tests:

  1. Key & Value Decoding Parity:
    Per the OpenTelemetry Resource SDK specification, , and = inside OTEL_RESOURCE_ATTRIBUTES keys as well as values must be percent-encoded. Applying parse.unquote(key.strip()) before inserting into env_resource_map ensures encoded delimiters like %2C and %3D in attribute keys decode consistently with values.
  2. Test Coverage:
    est_url_decode_keys exercises , (%2C), = (%3D), and space (%20) encodings in keys, verifying the resulting Resource attribute dictionary directly.
  3. Changelog Format:
    .changelog/5989.fixed follows the repository's towncrier format cleanly.

Solid fix.

@github-project-automation github-project-automation Bot moved this to Approved PRs in Python PR digest Dec 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved PRs

Development

Successfully merging this pull request may close these issues.

3 participants