diff --git a/CHANGELOG.md b/CHANGELOG.md index 925b8ab..36a4964 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - **[FEATURE]**: feat(capture): add support for capture tracepoints [#34](https://github.com/intergral/deep/pull/34) [@Umaaz](https://github.com/Umaaz) - **[BUGFIX]**: fix(duration): snapshot duration not set [#37](https://github.com/intergral/deep/pull/37) [@Umaaz](https://github.com/Umaaz) - **[BUGFIX]**: fix(attributes): snapshot attributes not set [#38](https://github.com/intergral/deep/pull/38) [@Umaaz](https://github.com/Umaaz) +- **[BUGFIX]**: fix(resource): discovered resources overwriting each other [#41](https://github.com/intergral/deep/pull/41) [@Umaaz](https://github.com/Umaaz) # 1.1.0 (06/02/2024) diff --git a/src/deep/api/plugin/otel.py b/src/deep/api/plugin/otel.py index f4cff7b..602213c 100644 --- a/src/deep/api/plugin/otel.py +++ b/src/deep/api/plugin/otel.py @@ -137,7 +137,7 @@ def resource(self) -> Optional[Resource]: # noinspection PyUnresolvedReferences resource = provider.resource attributes = dict(resource.attributes) - return Resource.create(attributes=attributes) + return Resource(attributes=attributes) return None def decorate(self, snapshot_id: str, context: ActionContext) -> Optional[BoundedAttributes]: diff --git a/src/deep/api/plugin/python.py b/src/deep/api/plugin/python.py index f38343b..50c3f9e 100644 --- a/src/deep/api/plugin/python.py +++ b/src/deep/api/plugin/python.py @@ -56,7 +56,7 @@ def resource(self) -> Optional[Resource]: :return: the provided resource """ - return Resource.create({ + return Resource({ "python_version": platform.python_version(), }) diff --git a/tests/unit_tests/api/plugin/test_otel.py b/tests/unit_tests/api/plugin/test_otel.py index 773a473..af2ddc7 100644 --- a/tests/unit_tests/api/plugin/test_otel.py +++ b/tests/unit_tests/api/plugin/test_otel.py @@ -19,6 +19,7 @@ from opentelemetry.sdk.trace import TracerProvider from deep.api.plugin.otel import OTelPlugin +from deep.api.resource import TELEMETRY_SDK_NAME class TestOtel(unittest.TestCase): @@ -35,6 +36,7 @@ def test_load_plugin(self): load_plugin = plugin.resource() self.assertIsNotNone(load_plugin) self.assertEqual("your-service-name", load_plugin.attributes.get(SERVICE_NAME)) + self.assertIsNone(load_plugin.attributes.get(TELEMETRY_SDK_NAME)) def test_collect_attributes(self): with trace.get_tracer_provider().get_tracer("test").start_as_current_span("test-span"): diff --git a/tests/unit_tests/api/resource/test_resource.py b/tests/unit_tests/api/resource/test_resource.py index 2edebbc..bf255db 100644 --- a/tests/unit_tests/api/resource/test_resource.py +++ b/tests/unit_tests/api/resource/test_resource.py @@ -35,6 +35,15 @@ def setUp(self) -> None: def tearDown(self) -> None: environ.pop(DEEP_RESOURCE_ATTRIBUTES) + def test_merge(self): + create = Resource.create() + new_resource = Resource.create({SERVICE_NAME: 'test'}) + self.assertEqual("unknown_service:python", create.attributes[SERVICE_NAME]) + self.assertEqual("test", new_resource.attributes[SERVICE_NAME]) + + merge = create.merge(new_resource) + self.assertEqual("test", merge.attributes[SERVICE_NAME]) + def test_create(self): attributes = { "service": "ui",