Skip to content

Commit

Permalink
Using new cloud resource id attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydvoss committed Oct 2, 2023
1 parent e318c94 commit c4c72e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
from opentelemetry.semconv.resource import ResourceAttributes, CloudPlatformValues, CloudProviderValues

_AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE = "azure.app.service.stamp"
# TODO: Remove once this resource attribute is no longer missing from SDK
_CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE = "cloud.resource_id"
_REGION_NAME = "REGION_NAME"
_WEBSITE_HOME_STAMPNAME = "WEBSITE_HOME_STAMPNAME"
_WEBSITE_HOSTNAME = "WEBSITE_HOSTNAME"
Expand Down Expand Up @@ -49,7 +47,7 @@ def detect(self) -> Resource:

azure_resource_uri = _get_azure_resource_uri(website_site_name)
if azure_resource_uri:
attributes[_CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE] = azure_resource_uri
attributes[ResourceAttributes.CLOUD_RESOURCE_ID] = azure_resource_uri
for (key, env_var) in _APP_SERVICE_ATTRIBUTE_ENV_VARS.items():
value = environ.get(env_var)
if value:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
from urllib.error import URLError

from opentelemetry.sdk.resources import ResourceDetector, Resource
from opentelemetry.semconv.resource import ResourceAttributes, CloudPlatformValues, CloudProviderValues
from opentelemetry.semconv.resource import (
ResourceAttributes,
CloudPlatformValues,
CloudProviderValues,
)


# TODO: Remove when cloud resource id is no longer missing in Resource Attributes
_CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE = "cloud.resource_id"
_AZURE_VM_METADATA_ENDPOINT = "http://169.254.169.254/metadata/instance/compute?api-version=2021-12-13&format=json"
_AZURE_VM_SCALE_SET_NAME_ATTRIBUTE = "azure.vm.scaleset.name"
_AZURE_VM_SKU_ATTRIBUTE = "azure.vm.sku"
Expand All @@ -35,7 +38,7 @@
ResourceAttributes.CLOUD_PLATFORM,
ResourceAttributes.CLOUD_PROVIDER,
ResourceAttributes.CLOUD_REGION,
_CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE,
ResourceAttributes.CLOUD_RESOURCE_ID,
ResourceAttributes.HOST_ID,
ResourceAttributes.HOST_NAME,
ResourceAttributes.HOST_TYPE,
Expand Down Expand Up @@ -81,7 +84,7 @@ def get_attribute_from_metadata(self, metadata_json, attribute_key):
ams_value = CloudProviderValues.AZURE.value
elif attribute_key == ResourceAttributes.CLOUD_REGION:
ams_value = metadata_json["location"]
elif attribute_key == _CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE:
elif attribute_key == ResourceAttributes.CLOUD_RESOURCE_ID:
ams_value = metadata_json["resourceId"]
elif attribute_key == ResourceAttributes.HOST_ID or \
attribute_key == ResourceAttributes.SERVICE_INSTANCE_ID:
Expand Down

0 comments on commit c4c72e2

Please sign in to comment.