Registry / observability / opencensus-ext-azure

opencensus-ext-azure

JSON →
library1.1.15pypypi✓ verified 24d ago

OpenCensus Azure Monitor Exporter is a Python library that enables applications to export telemetry data (traces, metrics, and logs) to Azure Monitor and Application Insights. It's part of the OpenCensus project, which is currently in maintenance mode, with OpenTelemetry being the recommended successor for new development. The library receives critical bug fixes but no new feature development. The current version is 1.1.15.

pip install opencensus-ext-azure
INSTALL
IMPORT
SIG · OPENCENSUS-EXT-AZU
O
opencensus-ext-azure
observabilitypythonv1.1.15
Install
5.5s avg
Import
Disk
55MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.1.15 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 54.7MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 5.5s · import 0.000s · 56MB
55MB installed
● package 55MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AzureMonitorTraceExporter
from opencensus.ext.azure.trace_exporter import AzureMonitorTraceExporter
from opencensus.ext.azure.trace_exporter import AzureMonitorTraceExporter

This quickstart demonstrates how to set up and use the `AzureMonitorTraceExporter` for distributed tracing and `AzureMonitorLogHandler` for sending application logs to Azure Application Insights. Ensure the `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable is set for telemetry to be sent successfully.

import os import logging from opencensus.ext.azure.log_exporter import AzureMonitorLogHandler from opencensus.ext.azure.trace_exporter import AzureMonitorTraceExporter from opencensus.trace.tracer import Tracer from opencensus.trace.samplers import ProbabilitySampler # Set your Azure Application Insights Connection String as an environment variable # APPLICATIONINSIGHTS_CONNECTION_STRING='InstrumentationKey=YOUR_INSTRUMENTATION_KEY;IngestionEndpoint=https://eastus-8.in.applicationinsights.azure.com/' CONNECTION_STRING = os.environ.get('APPLICATIONINSIGHTS_CONNECTION_STRING', '') if not CONNECTION_STRING: print("WARNING: APPLICATIONINSIGHTS_CONNECTION_STRING environment variable not set. Telemetry will not be sent.") # --- Tracing Example --- print("\n--- Tracing Example ---") # Initialize a trace exporter trace_exporter = AzureMonitorTraceExporter( connection_string=CONNECTION_STRING ) tracer = Tracer(exporter=trace_exporter, sampler=ProbabilitySampler(1.0)) with tracer.span(name='my_span'): print(" Inside a traced span.") with tracer.span(name='child_span'): print(" Inside a child span.") print(" Trace exported. Check Azure Portal after a short delay.") # --- Logging Example --- print("\n--- Logging Example ---") # Initialize a log handler handler = AzureMonitorLogHandler( connection_string=CONNECTION_STRING ) logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) logger.addHandler(handler) logger.info('This is an info log via Azure Monitor.') logger.warning('This is a warning log.') try: 1 / 0 except ZeroDivisionError: logger.exception('An error occurred during division.') print(" Logs exported. Check Azure Portal after a short delay.") # In a real application, ensure exporters are properly shut down on exit # trace_exporter.shutdown() # handler.close()
Debug
Known issues
breakingThe OpenCensus project, including `opencensus-ext-azure`, has officially transitioned to OpenTelemetry. While existing OpenCensus applications will continue to function, the project is in maintenance mode, meaning no new features will be added, and future development efforts are focused on OpenTelemetry. New applications should consider starting with OpenTelemetry.
fix
For new projects, consider adopting OpenTelemetry. For existing projects, plan for eventual migration to OpenTelemetry. Refer to OpenTelemetry's official documentation for migration guides.
affects: All versions
deprecatedActive feature development for `opencensus-ext-azure` has ceased. The library will only receive critical bug fixes. This impacts long-term support and access to new Azure Monitor features.
fix
Be aware that new features or integrations for Azure Monitor may only be available through the OpenTelemetry Azure Monitor Exporter. Consider migrating to OpenTelemetry for future-proof development.
affects: All versions >= 1.0.0
gotchaIt is recommended to use the `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable instead of `APPINSIGHTS_INSTRUMENTATIONKEY` for configuration. Connection strings offer more flexibility and security, supporting endpoint customization and other settings.
fix
Prefer setting the `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable with your Application Insights connection string. If specifying in code, pass `connection_string` argument to the exporter.
affects: All versions
gotchaWhen integrating logging, ensure you don't add duplicate `AzureMonitorLogHandler` instances to the same logger or its ancestors, as this can lead to logs being sent multiple times.
fix
Check `logger.handlers` before adding a new `AzureMonitorLogHandler`. For example: `if not any(isinstance(h, AzureMonitorLogHandler) for h in logger.handlers): logger.addHandler(handler)`
affects: All versions
gotchaCompatibility issues can arise if the `opencensus` core library version does not meet the requirements specified by `opencensus-ext-azure`. Always ensure `opencensus` is installed within the required range.
fix
Verify that your installed `opencensus` package satisfies the version constraint (`opencensus>=0.11.0,<1.0.0` for current `opencensus-ext-azure` versions). Use `pip install -U opencensus` to update, or `pip install 'opencensus>=0.11.0,<1.0.0'`.
affects: All versions
Upgrade
Version history
1.1.15latest on PyPI · released Jun 3, 2025
Audit
Dependencies
opencensusrequiredCore OpenCensus library for common API surfaces and context management.
azure-corerequiredMicrosoft Azure SDK for Python (Core) for shared Azure functionalities.
azure-functions-workeroptionalRequired for specific Azure Functions integration features.
Agent activity
48 hits · last 30 days
node
42
OpenAI (training)
2
Resources
opencensus-ext-azure — pip install opencensus-ext-azure · libregistry