Skip to content

Telemetry with Azure SDKs

Rakshith Bhyravabhotla edited this page Aug 2, 2021 · 3 revisions

All the Azure SDKs support distributed tracing, metric collection, and logging using the OpenCensus library. Through the use of Azure Monitor exporter, you will be able to send this collected telemetry to Application Insights.

More info on this can be found here.

OpenCensus integration with azure-core

Now you can use OpenCensus for Python as usual with any SDKs that is compatible with azure-core tracing.

Moreover, this can be done without the need to pass any context.

The following sample shows using tracing with Azure Monitor exporter.

from opencensus.ext.azure.trace_exporter import AzureExporter

from opencensus.trace.tracer import Tracer
from opencensus.trace.samplers import AlwaysOnSampler

from azure.storage.blob import BlobServiceClient

exporter = AzureExporter(
    instrumentation_key="uuid of the instrumentation key (see your Azure Monitor account)"
)

tracer = Tracer(exporter=exporter, sampler=AlwaysOnSampler())
with tracer.span(name="MyApplication") as span:
    client = BlobServiceClient.from_connection_string('connectionstring')
    client.delete_container('mycontainer')  # Call will be traced

Logging

A detailed explanation with a sample for logging can be found on https://docs.microsoft.com/azure/azure-monitor/app/opencensus-python#logs

Metrics

A detailed sample with explanation for collecting metrics can be found on https://docs.microsoft.com/azure/azure-monitor/app/opencensus-python#metrics