From 1fd0e16b9ead354eb0288fbd2e70f7cf48b17bed Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Wed, 7 Feb 2024 15:19:25 -0800 Subject: [PATCH 1/5] device --- .../azure-monitor-opentelemetry-exporter/CHANGELOG.md | 3 +++ .../azure/monitor/opentelemetry/exporter/_utils.py | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md b/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md index d973799d27b0..9028eb43edbc 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md @@ -4,6 +4,9 @@ ### Features Added +- Add device.* to part A fields + ([#33983](https://github.com/Azure/azure-sdk-for-python/pull/33983)) + ### Breaking Changes ### Bugs Fixed diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_utils.py b/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_utils.py index dc7c0b240f86..d70aeed0a6b5 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_utils.py +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_utils.py @@ -161,6 +161,9 @@ def _populate_part_a_fields(resource: Resource): service_name = resource.attributes.get(ResourceAttributes.SERVICE_NAME) service_namespace = resource.attributes.get(ResourceAttributes.SERVICE_NAMESPACE) service_instance_id = resource.attributes.get(ResourceAttributes.SERVICE_INSTANCE_ID) + device_id = resource.attributes.get(ResourceAttributes.DEVICE_ID) + device_model = resource.attributes.get(ResourceAttributes.DEVICE_MODEL_NAME) + device_make = resource.attributes.get(ResourceAttributes.DEVICE_MANUFACTURER) if service_name: if service_namespace: tags[ContextTagKeys.AI_CLOUD_ROLE] = str(service_namespace) + \ @@ -172,6 +175,12 @@ def _populate_part_a_fields(resource: Resource): else: tags[ContextTagKeys.AI_CLOUD_ROLE_INSTANCE] = platform.node() # hostname default tags[ContextTagKeys.AI_INTERNAL_NODE_NAME] = tags[ContextTagKeys.AI_CLOUD_ROLE_INSTANCE] + if device_id: + tags[ContextTagKeys.AI_DEVICE_ID] = device_id + if device_model: + tags[ContextTagKeys.AI_DEVICE_MODEL] = device_model + if device_make: + tags[ContextTagKeys.AI_DEVICE_OEM_NAME] = device_make return tags # pylint: disable=W0622 From 9c4771f09feaa205ad9628344bd4a78357aaed8c Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Thu, 8 Feb 2024 10:11:20 -0800 Subject: [PATCH 2/5] chagnelog --- .../azure-monitor-opentelemetry-exporter/CHANGELOG.md | 2 +- .../azure/monitor/opentelemetry/exporter/_utils.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md b/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md index 9028eb43edbc..3bba3b18c8a1 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md @@ -5,7 +5,7 @@ ### Features Added - Add device.* to part A fields - ([#33983](https://github.com/Azure/azure-sdk-for-python/pull/33983)) + ([#34229](https://github.com/Azure/azure-sdk-for-python/pull/34229)) ### Breaking Changes diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_utils.py b/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_utils.py index d70aeed0a6b5..27b31f7e34c6 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_utils.py +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_utils.py @@ -176,11 +176,11 @@ def _populate_part_a_fields(resource: Resource): tags[ContextTagKeys.AI_CLOUD_ROLE_INSTANCE] = platform.node() # hostname default tags[ContextTagKeys.AI_INTERNAL_NODE_NAME] = tags[ContextTagKeys.AI_CLOUD_ROLE_INSTANCE] if device_id: - tags[ContextTagKeys.AI_DEVICE_ID] = device_id + tags[ContextTagKeys.AI_DEVICE_ID] = device_id # type: ignore if device_model: - tags[ContextTagKeys.AI_DEVICE_MODEL] = device_model + tags[ContextTagKeys.AI_DEVICE_MODEL] = device_model # type: ignore if device_make: - tags[ContextTagKeys.AI_DEVICE_OEM_NAME] = device_make + tags[ContextTagKeys.AI_DEVICE_OEM_NAME] = device_make # type: ignore return tags # pylint: disable=W0622 From 4220515b74239c3957ff19e93baa70424c004229 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Thu, 8 Feb 2024 11:30:15 -0800 Subject: [PATCH 3/5] tests --- .../tests/test_utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_utils.py b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_utils.py index 52c951d11900..7ab00c9090f9 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_utils.py +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_utils.py @@ -48,12 +48,18 @@ def test_populate_part_a_fields(self): resource = Resource( {"service.name": "testServiceName", "service.namespace": "testServiceNamespace", - "service.instance.id": "testServiceInstanceId"}) + "service.instance.id": "testServiceInstanceId", + "device.id": "testDeviceId", + "device.model.name": "testDeviceModel", + "device.manufacturer": "testDeviceMake"}) tags = _utils._populate_part_a_fields(resource) self.assertIsNotNone(tags) self.assertEqual(tags.get("ai.cloud.role"), "testServiceNamespace.testServiceName") self.assertEqual(tags.get("ai.cloud.roleInstance"), "testServiceInstanceId") self.assertEqual(tags.get("ai.internal.nodeName"), "testServiceInstanceId") + self.assertEqual(tags.get("ai.device.id"), "testDeviceId") + self.assertEqual(tags.get("ai.device.model"), "testDeviceModel") + self.assertEqual(tags.get("ai.device.oemName"), "testDeviceMake") def test_populate_part_a_fields_default(self): resource = Resource( From 379e386589034de3ea39a0e8b334aa856b6f033c Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Thu, 8 Feb 2024 13:11:56 -0800 Subject: [PATCH 4/5] Update test_utils.py --- .../azure-monitor-opentelemetry-exporter/tests/test_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_utils.py b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_utils.py index 7ab00c9090f9..ac8950e7d535 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_utils.py +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_utils.py @@ -61,6 +61,7 @@ def test_populate_part_a_fields(self): self.assertEqual(tags.get("ai.device.model"), "testDeviceModel") self.assertEqual(tags.get("ai.device.oemName"), "testDeviceMake") + def test_populate_part_a_fields_default(self): resource = Resource( {"service.name": "testServiceName"}) From 838b59f2fba7e397c510a465bc5fe40bb84c6b9b Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Thu, 8 Feb 2024 13:12:02 -0800 Subject: [PATCH 5/5] Update test_utils.py --- .../azure-monitor-opentelemetry-exporter/tests/test_utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_utils.py b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_utils.py index ac8950e7d535..7ab00c9090f9 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_utils.py +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_utils.py @@ -61,7 +61,6 @@ def test_populate_part_a_fields(self): self.assertEqual(tags.get("ai.device.model"), "testDeviceModel") self.assertEqual(tags.get("ai.device.oemName"), "testDeviceMake") - def test_populate_part_a_fields_default(self): resource = Resource( {"service.name": "testServiceName"})