Skip to main content

Microsoft Azure Azure Core OpenTelemetry plugin Library for Python

Project description

Azure Core Tracing OpenTelemetry client library for Python

Getting started

Install the opentelemetry python for Python with pip:

pip install azure-core-tracing-opentelemetry --pre

Now 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 concepts

  • You don't need to pass any context, SDK will get it for you

  • Those lines are the only ones you need to enable tracing

      from azure.core.settings import settings
      from azure.core.tracing.ext.opentelemetry_span import OpenTelemetrySpan
      settings.tracing_implementation = OpenTelemetrySpan
    

Examples

There 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 SDKs
from azure.core.settings import settings
from azure.core.tracing.ext.opentelemetry_span import OpenTelemetrySpan

settings.tracing_implementation = OpenTelemetrySpan

# Example of Azure Monitor exporter, but you can use anything OpenTelemetry supports
from opentelemetry.ext.azure_monitor import AzureMonitorSpanExporter
exporter = AzureMonitorSpanExporter(
    instrumentation_key="uuid of the instrumentation key (see your Azure Monitor account)"
)

# Regular open telemetry usage from here, see https://github.com/open-telemetry/opentelemetry-python
# for details
from opentelemetry import trace
from opentelemetry.sdk.trace import Tracer
from opentelemetry.sdk.trace.export import ConsoleSpanExporter
from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor

# Simple console exporter
exporter = ConsoleSpanExporter()

trace.set_preferred_tracer_implementation(lambda T: Tracer())
tracer = trace.tracer()
tracer.add_span_processor(
    SimpleExportSpanProcessor(exporter)
)

# Example with Storage SDKs

from azure.storage.blob import BlobServiceClient

with tracer.start_as_current_span(name="MyApplication"):
    client = BlobServiceClient.from_connection_string('connectionstring')
    client.create_container('mycontainer')  # Call will be traced

Azure Exporter can be found in the package opentelemetry-azure-monitor-exporter

Troubleshooting

This client raises exceptions defined in Azure Core.

Next steps

More documentation on OpenTelemetry configuration can be found on the OpenTelemetry website

Contributing

This 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, visit https://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 the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Release History


1.0.0b1 Unreleased

Features

  • Opentelemetry implementation of azure-core tracing protocol

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for azure-core-tracing-opentelemetry, version 1.0.0b1
Filename, size File type Python version Upload date Hashes
Filename, size azure_core_tracing_opentelemetry-1.0.0b1-py2.py3-none-any.whl (6.0 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size azure-core-tracing-opentelemetry-1.0.0b1.zip (17.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page