HTTPX

Learn how to set up Sentry's HTTPX integration and how to capture outgoing HTTP requests as spans.

Sentry's HTTPX integration instruments outgoing HTTP requests using either the sync or the async HTTPX clients.

You need:

  • A Sentry account and project
  • Your application up and running
  • HTTPX 0.16+
  • Python 3.6+

Follow our quick start guide to set up Sentry in your Python application (make sure to enable tracing). Sentry's HTTPX integration is enabled automatically if you have the httpx package installed.

To verify that Sentry captures your HTTPX requests, add this code to your app, which will create a transaction called testing_sentry in the Traces section and create spans for the outgoing HTTP requests:

Copied
import sentry_sdk
import httpx

def main():
    # same as in the Python quick start guide (https://docs.sentry.io/platforms/python)
    sentry_sdk.init(...)

    # or sentry_sdk.traces.start_span(name="testing_sentry", parent_span=None) in stream mode
    with sentry_sdk.start_transaction(name="testing_sentry"):
        r1 = httpx.get("https://sentry.io/")
        r2 = httpx.post("http://httpbin.org/post")

main()

At this point, you should have integrated Sentry into your application and should already be sending data to your Sentry project.

Now's a good time to customize your setup and look into more advanced topics. Our next recommended steps for you are:

Are you having problems setting up the SDK or integration?
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").