Skip to main content

This package enables tracing http requests in a Requests Session via The OpenTracing Project. Once a production system contends with real concurrency or splits into many services, crucial (and formerly easy) tasks become difficult: user-facing latency optimization, root-cause analysis of backend errors, communication about distinct pieces of a now-distributed system, etc. Distributed tracing follows a request on its journey from inception to completion from mobile/browser all the way to the microservices.

As core services and libraries adopt OpenTracing, the application builder is no longer burdened with the task of adding basic tracing instrumentation to their own code. In this way, developers can build their applications with the tools they prefer and benefit from built-in tracing instrumentation. OpenTracing implementations exist for major distributed tracing systems and can be bound or swapped with a one-line configuration change.

If you want to learn more about the underlying Python API, visit the Python source code.

Installation

Run the following command:

$ pip install signalfx-instrumentation-requests

Usage

The provided requests.Session subclass allows the tracing of http methods using the OpenTracing API. All that it requires is for a SessionTracing instance to be initialized using an instance of an OpenTracing tracer and treated as a standard Requests session.

Initialize

SessionTracing takes the Tracer instance that is supported by OpenTracing and an optional dictionary of desired tags for each created span. You can also specify whether you’d like your current trace context to be propagated via http headers with your client request. To create a SessionTracing object, you can either pass in a tracer object directly or default to the opentracing.tracer global tracer that’s set elsewhere in your application:

from requests_opentracing import SessionTracing

opentracing_tracer = # some OpenTracing tracer implementation
traced_session = SessionTracing(opentracing_tracer, propagate=False,  # propagation allows distributed tracing in
                                span_tags=dict(my_helpful='tag'))     # upstream services you control (True by default).
resp = traced_session.get(my_url)

or

from requests_opentracing import SessionTracing
import opentracing
import requests

opentracing.tracer = # some OpenTracing tracer implementation
traced_session = SessionTracing()  # default to opentracing.tracer

You can now monkeypatch the requests.Session and requests.sessions.Session objects to point to the SessionTracing subclass for easier initialization:

from requests_opentracing import monkeypatch_requests

monkeypatch_requests()


from requests import Session

opentracing_tracer = # some OpenTracing tracer implementation
traced_session = Session(opentracing_tracer, propagate=False,  # Same arguments as provided to SessionTracing
                         span_tags=dict(my_helpful='tag'))
resp = traced_session.get(my_url)

Further Information

If you’re interested in learning more about the OpenTracing standard, please visit opentracing.io or join the mailing list. If you would like to implement OpenTracing in your project and need help, feel free to send us a note at community@opentracing.io.

Metadata

Release files for signalfx-instrumentation-requests 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for signalfx-instrumentation-requests 1.0.1
File Size Uploaded
signalfx-instrumentation-requests-1.0.1.tar.gz 4.3 kB Details

Release files / signalfx-instrumentation-requests-1.0.1.tar.gz

Download URL signalfx-instrumentation-requests-1.0.1.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ab528029adbe3c60e211f3773a08c8e660d43fd4f4c40513df5c3a6982da86e6
BLAKE2b-256 checksum
How to use checksums
d0b9fdd9f5cfe383dbc4422b2301278c8d5dcff7d2c3d0db4ee5ed83d5b43fe4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.8

Release history Release notifications | RSS feed

This release

1.0.1 This release

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page