Registry / observability / opencensus-ext-requests

opencensus-ext-requests

JSON →
library0.8.0pypypi✓ verified 85d ago

OpenCensus-ext-requests provides integration for the OpenCensus Python library to automatically trace HTTP requests made with the popular 'requests' package. OpenCensus is a set of libraries for collecting application metrics and distributed traces. The current version is 0.8.0. The OpenCensus project is largely in maintenance mode, having merged with OpenTracing to form OpenTelemetry, and users are encouraged to migrate.

pip install opencensus-ext-requests
INSTALL
IMPORT
SIG · OPENCENSUS-EXT-REQ
O
opencensus-ext-requests
observabilitypythonv0.8.0
Install
4.8s avg
Import
210ms
Disk
48MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.322s · 49MB
glibc
py 3.103.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.")
Debug
Known issues
breakingThe OpenCensus project is deprecated and has merged into OpenTelemetry. All OpenCensus GitHub repositories (except for the core `opencensus-python` repo) were archived on July 31, 2023. Users are strongly encouraged to migrate to OpenTelemetry for ongoing support, new features, and security patches.
fix
Migrate your instrumentation to OpenTelemetry. Official bridge libraries are available to facilitate a gradual migration.
affects: All versions
gotchaWhen combining `opencensus-ext-requests` and the `threading` integration with a synchronous exporter transport (e.g., `SyncTransport`), the application may freeze or hang indefinitely.
fix
Use an asynchronous exporter transport like `AsyncTransport` or avoid enabling both `threading` and `requests` integrations simultaneously if `SyncTransport` is necessary.
affects: <=0.8.0
gotchaWhen using `opencensus-ext-requests` with Azure Application Insights, the requests integration might create two spans, leading to broken dependency lineage in the Application Map.
fix
Implement a telemetry processor to override `envelope.data.baseData.type` to 'HTTP' for relevant spans, as detailed in various community discussions.
affects: <=0.8.0
Errors
Common errors & fixes
HTTP requests made with 'requests' are not appearing in traces.
The `requests` integration has not been enabled or configured correctly.
fix
Ensure `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`).
fix
Switch 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.
fix
Ensure 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.
Agent activity
28 hits · last 30 days
node
24
OpenAI (training)
2
Resources
opencensus-ext-requests — pip install opencensus-ext-requests · libregistry