{"id":1347,"library":"azure-core-tracing-opentelemetry","title":"Azure Core OpenTelemetry Tracing Plugin","description":"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.","status":"active","version":"1.0.0b12","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/core/azure-core-tracing-opentelemetry","tags":["azure","opentelemetry","tracing","observability","sdk","beta"],"install":[{"cmd":"pip install azure-core-tracing-opentelemetry opentelemetry-sdk opentelemetry-exporter-azure-monitor","lang":"bash","label":"Install with Azure Monitor exporter"},{"cmd":"pip install azure-core-tracing-opentelemetry opentelemetry-sdk","lang":"bash","label":"Install core tracing plugin"}],"dependencies":[{"reason":"Core library for Azure SDKs, providing the base tracing hooks.","package":"azure-core","optional":false},{"reason":"Required for OpenTelemetry API contracts.","package":"opentelemetry-api","optional":false},{"reason":"Required for OpenTelemetry SDK implementation (e.g., TracerProvider, SpanProcessor).","package":"opentelemetry-sdk","optional":false},{"reason":"Commonly used to export traces to Azure Monitor, but optional depending on your chosen exporter.","package":"opentelemetry-exporter-azure-monitor","optional":true}],"imports":[{"note":"This function simplifies enabling OpenTelemetry tracing for Azure SDK clients.","symbol":"use_opentelemetry","correct":"from azure.core.tracing.ext.opentelemetry_span import use_opentelemetry"},{"note":"The `OpenTelemetrySpan` class is located under the `ext` submodule.","wrong":"from azure.core.tracing.opentelemetry_span import OpenTelemetrySpan","symbol":"OpenTelemetrySpan","correct":"from azure.core.tracing.ext.opentelemetry_span import OpenTelemetrySpan"}],"quickstart":{"code":"import os\nfrom opentelemetry import trace\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor\nfrom azure.core.tracing.ext.opentelemetry_span import use_opentelemetry\nfrom azure.storage.blob import BlobServiceClient\n\n# 1. Set up OpenTelemetry TracerProvider and SpanProcessor\n# This example uses ConsoleSpanExporter; for Azure Monitor, use AzureMonitorTraceExporter\ntrace.set_tracer_provider(TracerProvider())\nspan_processor = SimpleSpanProcessor(ConsoleSpanExporter())\ntrace.get_tracer_provider().add_span_processor(span_processor)\n\n# 2. Enable OpenTelemetry tracing plugin for Azure SDK\nuse_opentelemetry()\n\n# 3. Create an Azure SDK client (e.g., Azure Blob Storage)\n# Ensure AZURE_STORAGE_CONNECTION_STRING is set in your environment for actual operations\nconnection_string = os.environ.get(\n    \"AZURE_STORAGE_CONNECTION_STRING\",\n    \"DefaultEndpointsProtocol=https;AccountName=test;AccountKey=test;BlobEndpoint=https://test.blob.core.windows.net/\"\n)\nif connection_string == \"DefaultEndpointsProtocol=https;AccountName=test;AccountKey=test;BlobEndpoint=https://test.blob.core.windows.net/\":\n    print(\"WARNING: Using a placeholder connection string. Tracing will run, but actual Azure operations will fail unless AZURE_STORAGE_CONNECTION_STRING is set.\")\n\nblob_service_client = BlobServiceClient.from_connection_string(connection_string)\n\n# 4. Perform an Azure SDK operation\ntry:\n    container_name = \"otel-test-container\"\n    container_client = blob_service_client.get_container_client(container_name)\n    print(f\"Attempting to create container '{container_name}'...\")\n    container_client.create_container()\n    print(f\"Container '{container_name}' created successfully.\")\n    print(f\"Attempting to delete container '{container_name}'...\")\n    container_client.delete_container()\n    print(f\"Container '{container_name}' deleted successfully.\")\nexcept Exception as e:\n    print(f\"An error occurred during Azure Storage operation (check your connection string and permissions): {e}\")\n\nprint(\"Traces should be printed to the console if successful and the connection string is valid.\")","lang":"python","description":"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."},"warnings":[{"fix":"Ensure `opentelemetry.trace.set_tracer_provider()` is called and at least one `SpanProcessor` is added to the `TracerProvider` before initializing Azure SDK clients.","message":"This 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Call `from azure.core.tracing.ext.opentelemetry_span import use_opentelemetry; use_opentelemetry()` at the very beginning of your application code.","message":"The 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"As 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.","severity":"breaking","affected_versions":"<1.0.0"},{"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.","message":"This 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}