diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py index 3088dbc5bbf..57feb43f96b 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py @@ -61,6 +61,7 @@ import os import sys import typing +from urllib import parse from json import dumps import pkg_resources @@ -289,7 +290,8 @@ def detect(self) -> "Resource": exc, ) continue - env_resource_map[key.strip()] = value.strip() + value_uri_decoded = parse.unquote(value.strip()) + env_resource_map[key.strip()] = value_uri_decoded service_name = os.environ.get(OTEL_SERVICE_NAME) if service_name: diff --git a/opentelemetry-sdk/tests/resources/test_resources.py b/opentelemetry-sdk/tests/resources/test_resources.py index 2d584981e62..48b7a5f477f 100644 --- a/opentelemetry-sdk/tests/resources/test_resources.py +++ b/opentelemetry-sdk/tests/resources/test_resources.py @@ -492,6 +492,13 @@ def test_invalid_key_value_pairs(self): resources.Resource({"k": "v", "k2": "v2", "foo": "bar=baz"}), ) + def test_multiple_with_uri_decode(self): + detector = resources.OTELResourceDetector() + os.environ[resources.OTEL_RESOURCE_ATTRIBUTES] = "key=value%20test%0A, key2=value+%202" + 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"},