Skip to content

Commit

Permalink
Add uri decode for OTEL_RESOUCE_ATTRIBUTES
Browse files Browse the repository at this point in the history
  • Loading branch information
shalevr committed Nov 21, 2022
1 parent 74ced85 commit eb5c744
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
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 uri decode values from OTEL_RESOURCE_ATTRIBUTES
([#3046](https://github.com/open-telemetry/opentelemetry-python/pull/3046))
- Add missing entry points for OTLP/HTTP exporter
([#3027](https://github.com/open-telemetry/opentelemetry-python/pull/3027))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import os
import sys
import typing
from urllib import parse
from json import dumps

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_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:
Expand Down
7 changes: 7 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,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"},
Expand Down

0 comments on commit eb5c744

Please sign in to comment.