Registry /
observability / opencensus-ext-requests
Install & Compatibility
Where this runs
tested against v0.8.0 · 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
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.322s · 49MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 4.8s · import 0.097s · 50MB
48MB installed
● package 48MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
config_integration
✓ from opencensus.trace import config_integration
Used to enable the Requests integration.
Tracer
✓ from opencensus.trace.tracer import Tracer
Essential for creating spans and managing the trace context.
ProbabilitySampler
✓ from opencensus.trace.samplers import ProbabilitySampler
Commonly used sampler for controlling trace collection rate.
requests
✓ import requests
The library being instrumented.
This quickstart demonstrates how to enable the `requests` integration, initialize a basic OpenCensus tracer, and perform an HTTP request. The `PrintExporter` is used to output trace data directly to the console for easy verification. The `config_integration.trace_integrations(['requests'])` call is crucial for automatically instrumenting `requests` calls.
import os
import requests
from opencensus.trace import config_integration
from opencensus.trace.tracer import Tracer
from opencensus.trace.samplers import ProbabilitySampler
from opencensus.trace.exporters import PrintExporter
# Enable the requests integration
config_integration.trace_integrations(['requests'])
# Configure a tracer with a sampler and an exporter
tracer = Tracer(
sampler=ProbabilitySampler(rate=1.0),
exporter=PrintExporter()
)
print("Making an HTTP request which will be traced...")
with tracer.span(name='parent_span'):
# The requests.get call below will be automatically traced
# and appear as a child span of 'parent_span'.
# Using a non-existent URL for demonstration, a real URL would work similarly.
try:
response = requests.get('http://non-existent-example.com/api/data')
print(f"Request completed with status: {response.status_code}")
except requests.exceptions.ConnectionError as e:
print(f"Connection error: {e}. This is expected for non-existent-example.com")
print("Trace data should have been printed to stdout by PrintExporter.")
Errors
Common errors & fixes
HTTP requests made with 'requests' are not appearing in traces.
The `requests` integration has not been enabled or configured correctly.
fixEnsure `opencensus.trace.config_integration.trace_integrations(['requests'])` is called before making `requests` calls and after initializing the tracer.
Application hangs or freezes when performing HTTP requests using the 'requests' library.
This often occurs when the `opencensus-ext-requests` integration is used in conjunction with the `threading` integration and a synchronous exporter transport (`SyncTransport`).
fixSwitch your exporter to use an asynchronous transport (e.g., `AsyncTransport`) or review your threading/requests integration strategy if `SyncTransport` is unavoidable.
Seeing duplicate log entries when using `opencensus-ext-azure` and a logger configured with `AzureLogHandler`.
The `AzureLogHandler` is likely being added multiple times to the same logger instance, a common issue with older or deprecated libraries.
fixEnsure that `AzureLogHandler` is added to your logger only once during application initialization. Check for multiple instantiations or reconfigurations of the logger.
Upgrade
Version history
0.8.0latest on PyPI · released Aug 3, 2022
Audit
Dependencies
requestsrequiredThis extension instruments the 'requests' library.
opencensusrequiredCore OpenCensus library required for tracing functionality.