Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include device.* attributes in part A fields #34229

Merged
merged 5 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

### Features Added

- Add device.* to part A fields
([#34229](https://github.com/Azure/azure-sdk-for-python/pull/34229))

### Breaking Changes

### Bugs Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) + \
Expand All @@ -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 # type: ignore
if device_model:
tags[ContextTagKeys.AI_DEVICE_MODEL] = device_model # type: ignore
if device_make:
tags[ContextTagKeys.AI_DEVICE_OEM_NAME] = device_make # type: ignore
return tags

# pylint: disable=W0622
lzchen marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading