Skip to content

Commit

Permalink
Using new cloud resource id attribute (open-telemetry#1976)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydvoss authored Oct 9, 2023
1 parent bb42e04 commit 3478831
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fix version of Flask dependency `werkzeug`
([#1980](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1980))
- `opentelemetry-resource-detector-azure` Using new Cloud Resource ID attribute.
([#1976](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1976))


## Version 1.20.0/0.41b0 (2023-09-01)
Expand Down
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 3478831

Please sign in to comment.