The `opentelemetry-resource-detector-azure` library provides an OpenTelemetry resource detector that automatically gathers Azure-specific metadata (e.g., cloud provider, region, resource ID) and adds it as attributes to exported telemetry data. It's part of the OpenTelemetry Python Contrib repository, currently at version 0.1.5, and follows the release cadence of the wider OpenTelemetry Python project, often receiving updates alongside core SDK releases.
pip install opentelemetry-sdk opentelemetry-resource-detector-azureVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the `AzureResourceDetector` and integrate it with the OpenTelemetry Python SDK. The detector automatically enriches telemetry with Azure-specific attributes. It requires Azure credentials (via environment variables or Managed Identity) to function correctly. The output on the console will include the automatically detected Azure resource attributes.
Ensure the application's identity has the necessary permissions to read Azure resource metadata. For local development, set `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, and `AZURE_CLIENT_SECRET` environment variables. For Azure deployments, prefer Managed Identities.
Understand that resource attributes are static for a given application run. If dynamic changes are needed, consider custom attributes on spans/metrics or restarting the application to re-initialize the SDK and re-detect resources.
Monitor application startup times. While usually negligible, in environments with strict startup time requirements or slow network egress, this could be a factor. The detector typically caches some results, but the initial fetch is network-dependent.