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

Add url decode for OTEL_RESOUCE_ATTRIBUTES #3046

Merged
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Add url decode values from OTEL_RESOURCE_ATTRIBUTES
([#3046](https://github.com/open-telemetry/opentelemetry-python/pull/3046))
- Fixed circular dependency issue with custom samplers
([#3026](https://github.com/open-telemetry/opentelemetry-python/pull/3026))
- Add missing entry points for OTLP/HTTP exporter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import sys
import typing
from json import dumps
from urllib import parse

import pkg_resources

Expand Down Expand Up @@ -289,7 +290,8 @@ def detect(self) -> "Resource":
exc,
)
continue
env_resource_map[key.strip()] = value.strip()
value_url_decoded = parse.unquote(value.strip())
env_resource_map[key.strip()] = value_url_decoded

service_name = os.environ.get(OTEL_SERVICE_NAME)
if service_name:
Expand Down
10 changes: 10 additions & 0 deletions opentelemetry-sdk/tests/resources/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,16 @@ def test_invalid_key_value_pairs(self):
resources.Resource({"k": "v", "k2": "v2", "foo": "bar=baz"}),
)

def test_multiple_with_url_decode(self):
detector = resources.OTELResourceDetector()
os.environ[
resources.OTEL_RESOURCE_ATTRIBUTES
] = "key=value%20test%0A, key2=value+%202"
lzchen marked this conversation as resolved.
Show resolved Hide resolved
self.assertEqual(
detector.detect(),
resources.Resource({"key": "value test\n", "key2": "value+ 2"}),
)

@mock.patch.dict(
os.environ,
{resources.OTEL_SERVICE_NAME: "test-srv-name"},
Expand Down