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 package

Install the opentelemetry python for Python with pip:

pip install azure-core-tracing-opentelemetry

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

# In the below example, we use a simple console exporter, uncomment these lines to use
# the Azure Monitor Exporter.
# Example of Azure Monitor exporter, but you can use anything OpenTelemetry supports
# from 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 TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter
from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor

# Simple console exporter
exporter = ConsoleSpanExporter()

trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)
trace.get_tracer_provider().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.0b7 (2020-10-05)

  • Pinned opentelemetry-api to version 0.13b0

1.0.0b6 (2020-07-06)

  • Pinned opentelemetry-api to version 0.10b0

1.0.0b5 (2020-06-08)

  • Pinned opentelemetry-api to version 0.8b0
  • Fixed a bug where DefaultSpan sometimes throws an AttributeError.

1.0.0b4 (2020-05-04)

  • link and link_from_headers now accepts attributes.

1.0.0b3 (2020-04-06)

Features

  • Pinned opentelemetry-api to version 0.6b0

1.0.0b2 (2020-03-09)

Features

  • Pinned opentelemetry-api to version 0.4a0

1.0.0b1

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.

Source Distribution

azure-core-tracing-opentelemetry-1.0.0b7.zip (18.7 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file azure-core-tracing-opentelemetry-1.0.0b7.zip.

File metadata

  • Download URL: azure-core-tracing-opentelemetry-1.0.0b7.zip
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.5

File hashes

Hashes for azure-core-tracing-opentelemetry-1.0.0b7.zip
Algorithm Hash digest
SHA256 9487821e5d93c9577b11a54b87335fb3b7ff7d77d52006d457ef96d09d4c090a
MD5 a5c54a70e27cd390cd1178c86d2c736a
BLAKE2b-256 91eac8694211eec9f17d293cfbc8e2c5100b793b7ae96db95668e0f5bb1677b5

See more details on using hashes here.

File details

Details for the file azure_core_tracing_opentelemetry-1.0.0b7-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for azure_core_tracing_opentelemetry-1.0.0b7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2d2f4f4381cc140de7045259f0f76de918ade0726f9f3fd9b76434d75c34b945
MD5 84d592c2290122ae205482b80f8959f0
BLAKE2b-256 02f618f86df4402b1c817ad1deacd19c176fd9a75450e6dbe03457eb17c397f9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page