OpenTelemetry Resource detectors for Azure
- This library contains OpenTelemetry Resource Detectors for the following Azure resources:
Installation
pip install opentelemetry-resource-detector-azure
Usage example for opentelemetry-resource-detector-azure
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.resource.detector.azure import (
AzureAKSResourceDetector,
AzureAppServiceResourceDetector,
AzureVMResourceDetector,
)
from opentelemetry.sdk.resources import get_aggregated_resources
trace.set_tracer_provider(
TracerProvider(
resource=get_aggregated_resources(
[
AzureAKSResourceDetector(),
AzureAppServiceResourceDetector(),
AzureVMResourceDetector(),
]
),
)
)
Mappings
The Azure Kubernetes Service Resource Detector reads the cluster resource ID from the CLUSTER_RESOURCE_ID environment variable or from a mounted aks-cluster-metadata ConfigMap at /etc/kubernetes/aks-cluster-metadata. It sets the following Resource Attributes:
cloud.platform set to azure.aks.
cloud.provider set to azure.
cloud.resource_id set to the full Azure Resource Manager cluster resource ID.
k8s.pod.name set to the value of the K8S_POD_NAME environment variable, when present.
k8s.pod.uid set to the value of the K8S_POD_UID environment variable, when present.
The native AKS ConfigMap is named aks-cluster-metadata and contains a clusterResourceId key. It can be exposed to a pod as an environment variable:
env:
- name: CLUSTER_RESOURCE_ID
valueFrom:
configMapKeyRef:
name: aks-cluster-metadata
key: clusterResourceId
Alternatively, mount the ConfigMap as a volume:
volumes:
- name: aks-cluster-metadata
configMap:
name: aks-cluster-metadata
volumeMounts:
- name: aks-cluster-metadata
mountPath: /etc/kubernetes/aks-cluster-metadata
Kubernetes resolves ConfigMap references within the pod’s namespace. Because the native ConfigMap is in kube-public, copy it into the workload namespace or use tooling such as an init container to expose its value through one of the supported locations.
To also populate pod identity, add these environment variables to your application container alongside either cluster metadata configuration above:
env:
- name: K8S_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: K8S_POD_UID
valueFrom:
fieldRef:
fieldPath: metadata.uid
The Kubernetes Downward API supplies the pod name and UID. Each attribute is optional and omitted if its environment variable is missing or empty. Pod identity is only populated when AKS cluster metadata is detected; the pod environment variables alone do not identify AKS. The detector does not infer pod identity from the hostname.
The detector is process-dependent so SDK post-fork resource refresh can re-run it in child processes.
The pod UID identifies the pod, not an individual service instance within it. It remains the same across container restarts within that pod and changes when the pod is replaced. The detector does not set or overwrite service.instance.id, since multiple containers or worker processes can run instances of the same service in one pod. Configure that attribute separately through your SDK resource or OTEL_RESOURCE_ATTRIBUTES with OTELResourceDetector.
- The Azure App Service Resource Detector sets the following Resource Attributes:
service.name set to the value of the WEBSITE_SITE_NAME environment variable.
cloud.platform set to azure_app_service.
cloud.provider set to azure.
cloud.resource_id set using the WEBSITE_RESOURCE_GROUP, WEBSITE_OWNER_NAME, and WEBSITE_SITE_NAME environment variables.
cloud.region set to the value of the REGION_NAME environment variable.
deployment.environment set to the value of the WEBSITE_SLOT_NAME environment variable.
host.id set to the value of the WEBSITE_HOSTNAME environment variable.
service.instance.id set to the value of the WEBSITE_INSTANCE_ID environment variable.
azure.app.service.stamp set to the value of the WEBSITE_HOME_STAMPNAME environment variable.
- The Azure VM Resource Detector sets the following Resource Attributes according to the response from the Azure Metadata Service:
azure.vm.scaleset.name set to the value of the vmScaleSetName field.
azure.vm.sku set to the value of the sku field.
cloud.platform set to the value of the azure_vm.
cloud.provider set to the value of the azure.
cloud.region set to the value of the location field.
cloud.resource_id set to the value of the resourceId field.
host.id set to the value of the vmId field.
host.name set to the value of the name field.
host.type set to the value of the vmSize field.
os.type set to the value of the osType field.
os.version set to the value of the version field.
service.instance.id set to the value of the vmId field.
- The Azure Functions Resource Detector is currently experimental. It sets the following Resource Attributes:
service.name set to the value of the WEBSITE_SITE_NAME environment variable.
process.id set to the process ID collected from the running process.
cloud.platform set to azure_functions.
cloud.provider set to azure.
cloud.resource_id set using the WEBSITE_RESOURCE_GROUP, WEBSITE_OWNER_NAME, and WEBSITE_SITE_NAME environment variables.
cloud.region set to the value of the REGION_NAME environment variable.
faas.instance set to the value of the WEBSITE_INSTANCE_ID environment variable.
faas.max_memory set to the value of the WEBSITE_MEMORY_LIMIT_MB environment variable converted from megabytes to bytes.
For more information, see the Semantic Conventions for Cloud Resource Attributes.
References
Metadata
Release files for opentelemetry-resource-detector-azure 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| opentelemetry_resource_detector_azure-0.4.0.tar.gz | 15.3 kB | Without provenance | Details for opentelemetry_resource_detector_azure-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| opentelemetry_resource_detector_azure-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for opentelemetry_resource_detector_azure-0.4.0-py3-none-any.whl |
Total release size: 30.1 kB
Release files / opentelemetry_resource_detector_azure-0.4.0.tar.gz
| Download URL | opentelemetry_resource_detector_azure-0.4.0.tar.gz |
|---|---|
| Size | 15.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5f0289e7874f753fecc34f66d97c2ba69adc3e283bf4474ac1eae7caf37bdddd
|
|
BLAKE2b-256 checksum How to use checksums |
80adad4f086cb0ec0e68d0d12e64da5b2fe2b1ad3297facfe28708ed63060b1d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.22
|
Release files / opentelemetry_resource_detector_azure-0.4.0-py3-none-any.whl
| Download URL | opentelemetry_resource_detector_azure-0.4.0-py3-none-any.whl |
|---|---|
| Size | 14.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9859d2ef07d451f6187cbd2138afd2322a5397759b45296cbeb66ef038cab51c
|
|
BLAKE2b-256 checksum How to use checksums |
aef0e5d9bcc1a6fb43c015ff3e68ece67e2e20e16a137156a2ca414879031d20
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.22
|
Security for opentelemetry-resource-detector-azure 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.