Registry / azure / opentelemetry-resource-detector-azure

opentelemetry-resource-detector-azure

JSON →
library0.2.0pypypi✓ verified 25d ago

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-azure
INSTALL
IMPORT
SIG · OPENTELEMETRY-RESO
O
opentelemetry-resource-detector-azure
azurepythonv0.2.0
Install
2.5s avg
Import
Disk
22MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 23.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.5s · import 0.000s · 25MB
22MB installed
● package 22MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AzureResourceDetector
from opentelemetry.sdk.extension.resource.azure import AzureResourceDetector
Resource
from opentelemetry.sdk.resources import Resource
TracerProvider
from opentelemetry.sdk.trace import TracerProvider
ConsoleSpanExporter
from opentelemetry.sdk.trace.export import ConsoleSpanExporter
SimpleSpanProcessor
from opentelemetry.sdk.trace.export import SimpleSpanProcessor

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.

import os from opentelemetry import trace from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor from opentelemetry.sdk.extension.resource.azure import AzureResourceDetector # Configure Azure credentials via environment variables for testing purposes # In a real Azure environment, Managed Identity is often preferred. # For local testing, ensure these are set: # os.environ['AZURE_CLIENT_ID'] = os.environ.get('AZURE_CLIENT_ID', '') # os.environ['AZURE_TENANT_ID'] = os.environ.get('AZURE_TENANT_ID', '') # os.environ['AZURE_CLIENT_SECRET'] = os.environ.get('AZURE_CLIENT_SECRET', '') # Instantiate and register the Azure Resource Detector # The detector makes network calls to Azure APIs, potentially adding startup latency. # Resource attributes are collected at SDK initialization and are immutable. resource = Resource.create([AzureResourceDetector()]) # Set up a TracerProvider with the detected resource provider = TracerProvider(resource=resource) processor = SimpleSpanProcessor(ConsoleSpanExporter()) provider.add_span_processor(processor) trace.set_tracer_provider(provider) # Get a tracer and create a simple span tracer = trace.get_tracer(__name__) with tracer.start_as_current_span("azure-resource-test-span") as span: span.set_attribute("my.custom.attribute", "hello") print("Span created. Check console for resource attributes from Azure.") # Ensure all spans are processed and exported on shutdown provider.shutdown()
Debug
Known issues
gotchaThe Azure Resource Detector requires appropriate Azure credentials and permissions (e.g., Contributor role on the resource group or specific Reader permissions) to query Azure Resource Manager APIs. Without correct authentication (e.g., Managed Identity or `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET` environment variables), the detector will fail to gather metadata, resulting in missing or incomplete resource attributes.
fix
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.
affects: >=0.1.0
gotchaResource attributes are collected at SDK initialization time and are immutable throughout the application's lifecycle. Any changes to the Azure environment or the running resource's metadata after the application starts will not be reflected in the telemetry emitted by the current application instance.
fix
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.
affects: >=0.1.0
gotchaThe Azure Resource Detector makes network calls to Azure APIs during application startup to fetch resource metadata. This can introduce latency during the initialization phase of your application. Ensure robust network connectivity and consider the performance implications in latency-sensitive applications.
fix
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.
affects: >=0.1.0
Upgrade
Version history
0.2.0latest on PyPI · released Aug 20, 2026
Audit
Dependencies
opentelemetry-sdkrequiredCore OpenTelemetry SDK components are required for any detector.
azure-identityrequiredRequired for authenticating to Azure Resource Manager to fetch metadata.
Agent activity
31 hits · last 30 days
node
28
OpenAI (training)
1
Resources
opentelemetry-resource-detector-azure — pip install opentelemetry-resource-detector-azure · libregistry