Requests
See every HTTP request your app makes with requests: the URL, the response status, how
long it took, and any errors, as a span (one unit of work with a name, a start, and a duration)
in Logfire. Related spans link together into a trace (the full journey of one request), so a slow
outgoing call shows up right next to the code that triggered it.
- Each request as a span, with its URL, method, response status, and duration
- Any errors that occurred during the request
You’ll need a Logfire project. Open Add data in your project (top navigation) and follow the
setup for your language: it signs your machine in with logfire auth (a browser sign-in, no token
to copy) and, for production or other languages, creates a write token (the credential your app
uses to send data). New to Logfire? Start with Getting Started.
Install logfire with the requests extra:
pip install 'logfire[requests]'
uv add 'logfire[requests]'
Add two lines to your app: logfire.configure() to connect to your project, and
logfire.instrument_requests() to record every request.
import requests
import logfire
logfire.configure()
logfire.instrument_requests()
requests.get('https://httpbin.org/get')
Run it with python main.py.
Run your program, then open your project in the
Logfire web app and go to the Live view. Within a few seconds you
should see a span for the GET request. Click it to see the URL, response status, and how long it
took.
Not seeing your requests in Logfire? Check these first:
logfire.configure()runs beforelogfire.instrument_requests(). Configure the connection first, then instrument.- You call
instrument_requests()exactly once. - Your write token is set. In local development, run
logfire projects use <your-project>; in production, set theLOGFIRE_TOKENenvironment variable. See Getting Started. - You actually made a request. Spans appear only after a request completes.
logfire.instrument_requests() accepts additional keyword
arguments and passes them to the OpenTelemetry Requests instrumentation. See
their documentation for the full list.
- API reference:
logfire.instrument_requests() - Underlying OpenTelemetry package: Requests instrumentation