From d7a5242006e3d5169acfe55f6bfc1055989ab34f Mon Sep 17 00:00:00 2001 From: Ben Donnelly Date: Mon, 19 Feb 2024 10:13:25 +0000 Subject: [PATCH 1/3] fix(bug): resource where created with defaults overwriting the discovered values --- src/deep/api/plugin/otel.py | 2 +- src/deep/api/plugin/python.py | 2 +- tests/unit_tests/api/resource/test_resource.py | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/deep/api/plugin/otel.py b/src/deep/api/plugin/otel.py index d0064ca..2e0f82c 100644 --- a/src/deep/api/plugin/otel.py +++ b/src/deep/api/plugin/otel.py @@ -129,7 +129,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, context: ActionContext) -> Optional[BoundedAttributes]: diff --git a/src/deep/api/plugin/python.py b/src/deep/api/plugin/python.py index 22d7e38..62c630a 100644 --- a/src/deep/api/plugin/python.py +++ b/src/deep/api/plugin/python.py @@ -55,7 +55,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/resource/test_resource.py b/tests/unit_tests/api/resource/test_resource.py index 2edebbc..b544ebf 100644 --- a/tests/unit_tests/api/resource/test_resource.py +++ b/tests/unit_tests/api/resource/test_resource.py @@ -35,6 +35,16 @@ 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", From 54ba2b4e073278d7f6b3ede623642097c46d72ff Mon Sep 17 00:00:00 2001 From: Ben Donnelly Date: Mon, 19 Feb 2024 18:12:26 +0000 Subject: [PATCH 2/3] fix(bug): fix formatting update CHANGELOG.md --- CHANGELOG.md | 1 + tests/unit_tests/api/resource/test_resource.py | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) 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/tests/unit_tests/api/resource/test_resource.py b/tests/unit_tests/api/resource/test_resource.py index b544ebf..bf255db 100644 --- a/tests/unit_tests/api/resource/test_resource.py +++ b/tests/unit_tests/api/resource/test_resource.py @@ -44,7 +44,6 @@ def test_merge(self): merge = create.merge(new_resource) self.assertEqual("test", merge.attributes[SERVICE_NAME]) - def test_create(self): attributes = { "service": "ui", From feec48b6081afddb6215794fc1aa780baf68833a Mon Sep 17 00:00:00 2001 From: Ben Donnelly Date: Mon, 19 Feb 2024 18:20:39 +0000 Subject: [PATCH 3/3] fix(resource): add explicit check in test --- tests/unit_tests/api/plugin/test_otel.py | 2 ++ 1 file changed, 2 insertions(+) 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"):