Skip to content

Commit 331d32d

Browse files
lzchensofiar-msft
authored andcommitted
Include device.* attributes in part A fields (Azure#34229)
1 parent dd38b6f commit 331d32d

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
### Features Added
66

7+
- Add device.* to part A fields
8+
([#34229](https://github.com/Azure/azure-sdk-for-python/pull/34229))
9+
710
### Breaking Changes
811

912
### Bugs Fixed

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ def _populate_part_a_fields(resource: Resource):
161161
service_name = resource.attributes.get(ResourceAttributes.SERVICE_NAME)
162162
service_namespace = resource.attributes.get(ResourceAttributes.SERVICE_NAMESPACE)
163163
service_instance_id = resource.attributes.get(ResourceAttributes.SERVICE_INSTANCE_ID)
164+
device_id = resource.attributes.get(ResourceAttributes.DEVICE_ID)
165+
device_model = resource.attributes.get(ResourceAttributes.DEVICE_MODEL_NAME)
166+
device_make = resource.attributes.get(ResourceAttributes.DEVICE_MANUFACTURER)
164167
if service_name:
165168
if service_namespace:
166169
tags[ContextTagKeys.AI_CLOUD_ROLE] = str(service_namespace) + \
@@ -172,6 +175,12 @@ def _populate_part_a_fields(resource: Resource):
172175
else:
173176
tags[ContextTagKeys.AI_CLOUD_ROLE_INSTANCE] = platform.node() # hostname default
174177
tags[ContextTagKeys.AI_INTERNAL_NODE_NAME] = tags[ContextTagKeys.AI_CLOUD_ROLE_INSTANCE]
178+
if device_id:
179+
tags[ContextTagKeys.AI_DEVICE_ID] = device_id # type: ignore
180+
if device_model:
181+
tags[ContextTagKeys.AI_DEVICE_MODEL] = device_model # type: ignore
182+
if device_make:
183+
tags[ContextTagKeys.AI_DEVICE_OEM_NAME] = device_make # type: ignore
175184
return tags
176185

177186
# pylint: disable=W0622

sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,18 @@ def test_populate_part_a_fields(self):
4848
resource = Resource(
4949
{"service.name": "testServiceName",
5050
"service.namespace": "testServiceNamespace",
51-
"service.instance.id": "testServiceInstanceId"})
51+
"service.instance.id": "testServiceInstanceId",
52+
"device.id": "testDeviceId",
53+
"device.model.name": "testDeviceModel",
54+
"device.manufacturer": "testDeviceMake"})
5255
tags = _utils._populate_part_a_fields(resource)
5356
self.assertIsNotNone(tags)
5457
self.assertEqual(tags.get("ai.cloud.role"), "testServiceNamespace.testServiceName")
5558
self.assertEqual(tags.get("ai.cloud.roleInstance"), "testServiceInstanceId")
5659
self.assertEqual(tags.get("ai.internal.nodeName"), "testServiceInstanceId")
60+
self.assertEqual(tags.get("ai.device.id"), "testDeviceId")
61+
self.assertEqual(tags.get("ai.device.model"), "testDeviceModel")
62+
self.assertEqual(tags.get("ai.device.oemName"), "testDeviceMake")
5763

5864
def test_populate_part_a_fields_default(self):
5965
resource = Resource(

0 commit comments

Comments
 (0)