Package: azure-core-tracing-opentelemetry
Azure Core Tracing OpenTelemetry client library for PythonGetting startedInstall the packageInstall the Azure Core OpenTelemetry Tracing plugin for Python withpip:pipinstallazure-core-tracing-opentelemetryNow you can use OpenTelemetry for Python as usual with any SDKs that are compatible
with azure-core tracing. This includes (not exhaustive list), azure-storage-blob, azure-keyvault-secrets, azure-eventhub, etc.Key conceptsYou don't need to pass any context, SDK will get it for youThere are two ways to enable the tracing plugin in code:fromazure.core.settingsimportsettingsfromazure.core.tracing.ext.opentelemetry_spanimportOpenTelemetrySpansettings.tracing_implementation=OpenTelemetrySpanorfromazure.core.settingsimportsettingssettings.tracing_implementation="opentelemetry"Alternatively, if you have the latest version ofazure-coreinstalled, you can also set the following environment variable to enable tracing with OpenTelemetry:AZURE_SDK_TRACING_IMPLEMENTATION=opentelemetryExamplesThere is no explicit context to pass, you just create your usual opentelemetry tracer and
call any SDK code that is compatible with azure-core tracing. This is an example
using Azure Monitor exporter, but you can use any exporter (Zipkin, etc.).# Declare OpenTelemetry as enabled tracing plugin for Azure SDKsfromazure.core.settingsimportsettingssettings.tracing_implementation="opentelemetry"# In the below example, we use a simple console exporter, uncomment these lines to use# the OpenTelemetry exporter for Azure Monitor.# Example of a trace exporter for Azure Monitor, but you can use anything OpenTelemetry supports# from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter# exporter = AzureMonitorTraceExporter(#     connection_string="the connection string used for your Application Insights resource"# )# Regular open telemetry usage from here, see https://github.com/open-telemetry/opentelemetry-python# for detailsfromopentelemetryimporttracefromopentelemetry.sdk.traceimportTracerProviderfromopentelemetry.sdk.trace.exportimportConsoleSpanExporterfromopentelemetry.sdk.trace.exportimportSimpleSpanProcessor# Simple console exporterexporter=ConsoleSpanExporter()trace.set_tracer_provider(TracerProvider())tracer=trace.get_tracer(__name__)trace.get_tracer_provider().add_span_processor(SimpleSpanProcessor(exporter))# Example with Storage SDKsfromazure.storage.blobimportBlobServiceClientwithtracer.start_as_current_span(name="MyApplication"):client=BlobServiceClient.from_connection_string('connectionstring')client.create_container('my_container')# Call will be tracedThe Azure Monitor OpenTelemetry Exporter can be found in theazure-monitor-opentelemetry-exporterpackage.HTTP instrumentationWith the Azure Core OpenTelemetry Tracing plugin enabled, HTTP requests made by Azure SDK clients are typically instrumented via theDistributedTracingPolicyautomatically. Since Azure Core handles HTTP instrumentation for Azure service calls, automatic HTTP instrumentation from other libraries such asopentelemetry-requests-instrumentationare suppressed to avoid duplicate spans from being created.TroubleshootingThis client raises exceptions defined inAzure Core.Next stepsMore documentation on OpenTelemetry configuration can be found on theOpenTelemetry websiteContributingThis project welcomes contributions and suggestions.  Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visithttps://cla.microsoft.com.When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.This project has adopted theMicrosoft Open Source Code of Conduct. For more information see theCode of Conduct FAQor contactopencode@microsoft.comwith any additional questions or comments.Release History1.0.0b11 (2023-09-07)Bugs FixedFixedOpenTelemetrySpantyping to correctly implement theAbstractSpanprotocol. (#31943)1.0.0b10 (2023-07-11)Features AddedEnabled the use of thecontextkeyword argument for passing in context headers of a parent span. This will be the parent context used when creating the span. (#30411)Breaking ChangesRemapped certain attributes to converge with OpenTelemetry semantic conventions (#29203):x-ms-client-request-id->az.client_request_id,x-ms-request-id->az.service_request_id,http.user_agent->user_agent.original,message_bus.destination->messaging.destination.name,peer.address->net.peer.name,Other ChangesPython 2.7 is no longer supported. Please use Python version 3.7 or later.Nested internal spans are now suppressed with just the outermost internal span being recorded. Nested client spans will be children of the outermost span. (#29616)When client spans are created, a flag is set to indicate that automatic HTTP instrumentation should be suppressed. Since azure-core already instruments HTTP calls, this prevents duplicate spans from being produced. (#29616)Schema URL is now set on the tracer's instrumentation scope. (#30014)Minimumopentelemetry-apidependency bumped to1.12.0.Minimumazure-coredependency bumped to1.24.0.1.0.0b9 (2021-04-06)Updated opentelemetry-api to version 1.0.0LinkandSpanKindcan now be added while creating the span instance.1.0.0b8 (2021-02-08)Pinned opentelemetry-api to version 0.17b01.0.0b7 (2020-10-05)Pinned opentelemetry-api to version 0.13b01.0.0b6 (2020-07-06)Pinned opentelemetry-api to version 0.10b01.0.0b5 (2020-06-08)Pinned opentelemetry-api to version 0.8b0Fixed a bug whereDefaultSpansometimes throws an AttributeError.1.0.0b4 (2020-05-04)linkandlink_from_headersnow accepts attributes.1.0.0b3 (2020-04-06)FeaturesPinned opentelemetry-api to version 0.6b01.0.0b2 (2020-03-09)FeaturesPinned opentelemetry-api to version 0.4a01.0.0b1FeaturesOpentelemetry implementation of azure-core tracing protocol