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

Using new cloud resource id attribute #1976

Merged
merged 2 commits into from
Oct 9, 2023
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
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
Loading