Registry / azure / azure-core-tracing-opentelemetry

azure-core-tracing-opentelemetry

JSON →
library1.0.0b13pypypi✓ verified 25d ago

This library provides an OpenTelemetry plugin for `azure-core`, enabling automatic distributed tracing for Python Azure SDK client library calls. It integrates with your OpenTelemetry setup to propagate context and create spans for Azure service interactions. The current version is `1.0.0b12`, indicating a beta release, and it is actively maintained as part of the broader Azure SDK for Python.

pip install azure-core-tracing-opentelemetry opentelemetry-sdk opentelemetry-exporter-azure-monitor
INSTALL
IMPORT
SIG · AZURE-CORE-TRACING
A
azure-core-tracing-opentelemetry
azurepythonv1.0.0b13
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.0b13 · 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
glibc
py 3.10
1/2 runs
1/2 runs
py 3.11
1/2 runs
1/2 runs
py 3.12
1/2 runs
1/2 runs
py 3.13
1/2 runs
1/2 runs
py 3.9
1/2 runs
1/2 runs
Code
Verified usage

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

use_opentelemetry
from azure.core.tracing.ext.opentelemetry_span import use_opentelemetry
This function simplifies enabling OpenTelemetry tracing for Azure SDK clients.
OpenTelemetrySpan
from azure.core.tracing.ext.opentelemetry_span import OpenTelemetrySpan
from azure.core.tracing.opentelemetry_span import OpenTelemetrySpan
The `OpenTelemetrySpan` class is located under the `ext` submodule.

This quickstart demonstrates how to set up OpenTelemetry tracing for Azure SDK operations. It configures a simple console exporter, enables the `azure-core` OpenTelemetry plugin, and then performs a basic Azure Blob Storage operation. Traces for the Blob Storage client calls will be output to the console.

import os from opentelemetry import trace from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor from azure.core.tracing.ext.opentelemetry_span import use_opentelemetry from azure.storage.blob import BlobServiceClient # 1. Set up OpenTelemetry TracerProvider and SpanProcessor # This example uses ConsoleSpanExporter; for Azure Monitor, use AzureMonitorTraceExporter trace.set_tracer_provider(TracerProvider()) span_processor = SimpleSpanProcessor(ConsoleSpanExporter()) trace.get_tracer_provider().add_span_processor(span_processor) # 2. Enable OpenTelemetry tracing plugin for Azure SDK use_opentelemetry() # 3. Create an Azure SDK client (e.g., Azure Blob Storage) # Ensure AZURE_STORAGE_CONNECTION_STRING is set in your environment for actual operations connection_string = os.environ.get( "AZURE_STORAGE_CONNECTION_STRING", "DefaultEndpointsProtocol=https;AccountName=test;AccountKey=test;BlobEndpoint=https://test.blob.core.windows.net/" ) if connection_string == "DefaultEndpointsProtocol=https;AccountName=test;AccountKey=test;BlobEndpoint=https://test.blob.core.windows.net/": print("WARNING: Using a placeholder connection string. Tracing will run, but actual Azure operations will fail unless AZURE_STORAGE_CONNECTION_STRING is set.") blob_service_client = BlobServiceClient.from_connection_string(connection_string) # 4. Perform an Azure SDK operation try: container_name = "otel-test-container" container_client = blob_service_client.get_container_client(container_name) print(f"Attempting to create container '{container_name}'...") container_client.create_container() print(f"Container '{container_name}' created successfully.") print(f"Attempting to delete container '{container_name}'...") container_client.delete_container() print(f"Container '{container_name}' deleted successfully.") except Exception as e: print(f"An error occurred during Azure Storage operation (check your connection string and permissions): {e}") print("Traces should be printed to the console if successful and the connection string is valid.")
Debug
Known issues
gotchaThis package only provides the OpenTelemetry plugin for Azure Core. Users are responsible for explicitly setting up the OpenTelemetry SDK (TracerProvider, SpanProcessor, Exporter) separately. Forgetting this step will result in no traces being generated.
fix
Ensure `opentelemetry.trace.set_tracer_provider()` is called and at least one `SpanProcessor` is added to the `TracerProvider` before initializing Azure SDK clients.
affects: All versions
gotchaThe OpenTelemetry plugin must be explicitly enabled using `use_opentelemetry()` or by manually setting `azure.core.settings.settings.tracing_implementation` and `azure.core.settings.settings.tracing_manager` early in your application's lifecycle, before any Azure SDK clients are instantiated.
fix
Call `from azure.core.tracing.ext.opentelemetry_span import use_opentelemetry; use_opentelemetry()` at the very beginning of your application code.
affects: All versions
breakingAs a beta release (`1.0.0b12`), the API or internal behavior of this library may change in future versions, potentially introducing breaking changes before a stable `1.0.0` release.
fix
Monitor release notes carefully for future beta and stable versions. Pin to specific beta versions if stability is critical for your current development phase.
affects: <1.0.0
gotchaThis library has strict dependency requirements on `opentelemetry-api` and `opentelemetry-sdk` versions (e.g., `>=1.15.0, <2.0.0`). Incompatible versions of the OpenTelemetry SDK can lead to runtime errors or tracing failures.
fix
Always install the required OpenTelemetry packages alongside this library (`pip install azure-core-tracing-opentelemetry opentelemetry-sdk`) to ensure compatible versions are pulled in. Avoid manual installation of incompatible OpenTelemetry versions.
affects: All versions
gotchaThis library implicitly requires `opentelemetry-exporter-azure-monitor` for full functionality, but this package might not be automatically installed by default and can lead to installation failures if not explicitly provided or discoverable.
fix
Ensure `opentelemetry-exporter-azure-monitor` is explicitly installed alongside this library (e.g., `pip install azure-core-tracing-opentelemetry opentelemetry-sdk opentelemetry-exporter-azure-monitor`) to prevent installation errors and ensure complete tracing capabilities.
affects: All versions
gotchaThe `opentelemetry-exporter-azure-monitor` package, commonly used with this library for exporting traces to Azure Monitor, could not be found. This issue may arise if the package is not yet released or available for your specific Python version or platform (e.g., Python 3.13).
fix
Verify the availability of `opentelemetry-exporter-azure-monitor` for your Python environment. Consider using a different Python version or platform where the package is known to be available, or monitor its release status for future compatibility.
affects: All versions
Upgrade
Version history
1.0.0b13latest on PyPI · released May 1, 2026
Audit
Dependencies
azure-corerequiredCore library for Azure SDKs, providing the base tracing hooks.
opentelemetry-apirequiredRequired for OpenTelemetry API contracts.
opentelemetry-sdkrequiredRequired for OpenTelemetry SDK implementation (e.g., TracerProvider, SpanProcessor).
opentelemetry-exporter-azure-monitoroptionalCommonly used to export traces to Azure Monitor, but optional depending on your chosen exporter.
Agent activity
46 hits · last 30 days
node
40
OpenAI (training)
1
Resources
azure-core-tracing-opentelemetry — pip install azure-core-tracing-opentelemetry · libregistry