Skip to main content

OpenTracing support for Requests

Project description

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 requests-opentracing

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Requests-OpenTracing-0.3.0.tar.gz (4.2 kB view details)

Uploaded Source

File details

Details for the file Requests-OpenTracing-0.3.0.tar.gz.

File metadata

  • Download URL: Requests-OpenTracing-0.3.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.6.11

File hashes

Hashes for Requests-OpenTracing-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a8d28ae13c49bc6fccf3c8a84c9ad23113e15f8a2a28502ed701011b2e92cb52
MD5 b6b78521f0092beb02836007897da531
BLAKE2b-256 0fa3b0c18a20042aec5d2cb6724123752167895c4873a90ff59de91f2ddc3432

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page