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 Azure Core OpenTelemetry Tracing plugin 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

  • These 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
    
  • Alternatively, if you have the latest version of azure-core installed, you can also set the following environment variable to enable tracing with OpenTelemetry:

    AZURE_SDK_TRACING_IMPLEMENTATION=opentelemetry
    

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 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 details
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter
from opentelemetry.sdk.trace.export import SimpleSpanProcessor

# Simple console exporter
exporter = ConsoleSpanExporter()

trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)
trace.get_tracer_provider().add_span_processor(
    SimpleSpanProcessor(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('my_container')  # Call will be traced

The Azure Monitor OpenTelemetry 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.0b10 (2023-07-11)

Features Added

  • Enabled the use of the context keyword argument for passing in context headers of a parent span. This will be the parent context used when creating the span. (#30411)

Breaking Changes

  • Remapped 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 Changes

  • Python 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)
  • Minimum opentelemetry-api dependency bumped to 1.12.0.
  • Minimum azure-core dependency bumped to 1.24.0.

1.0.0b9 (2021-04-06)

  • Updated opentelemetry-api to version 1.0.0
  • Link and SpanKind can now be added while creating the span instance.

1.0.0b8 (2021-02-08)

  • Pinned opentelemetry-api to version 0.17b0

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.0b10.zip (34.6 kB view details)

Uploaded Source

Built Distribution

File details

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

File metadata

File hashes

Hashes for azure-core-tracing-opentelemetry-1.0.0b10.zip
Algorithm Hash digest
SHA256 0fc3ae08dc743873da82a7341d9f173bac3a45120c396e566c5ae27f8886d1fa
MD5 cf3fdfd159cc38618cea43488fd83c9e
BLAKE2b-256 a8398e5c69a189e43fb3ada504b439b16d1a8851ecc2ce13b489e3067f5eadbd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for azure_core_tracing_opentelemetry-1.0.0b10-py3-none-any.whl
Algorithm Hash digest
SHA256 46f045d8fab8dd7e0a7e96a758a2783613484e9fb246380de102e36c044d0ddc
MD5 a13010d0da255a999e1be0b553b990e7
BLAKE2b-256 b97049be9b1f508dedb669f5d1a10283141269787637245520acb7d2418b6629

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