Skip to content

HTTPX

The logfire.instrument_httpx() method can be used to instrument HTTPX with Logfire.

Installation

Install logfire with the httpx extra:

pip install 'logfire[httpx]'
rye add logfire -E httpx
poetry add 'logfire[httpx]'
uv add 'logfire[httpx]'

Usage

Let's see a minimal example below. You can run it with python main.py:

main.py
import logfire
import httpx

logfire.configure()
logfire.instrument_httpx()

url = "https://httpbin.org/get"

with httpx.Client() as client:
    client.get(url)


async def main():
    async with httpx.AsyncClient() as client:
        await client.get(url)


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

logfire.instrument_httpx() uses the OpenTelemetry HTTPX Instrumentation package, which you can find more information about here.