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]'
uv add 'logfire[httpx]'
rye add logfire -E httpx
poetry add 'logfire[httpx]'
Usage¶
Let's see a minimal example below. You can run it with python main.py
:
main.py
import asyncio
import httpx
import logfire
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)
asyncio.run(main())
main.py
import asyncio
import httpx
import logfire
logfire.configure()
url = 'https://httpbin.org/get'
with httpx.Client() as client:
logfire.instrument_httpx(client)
client.get(url)
async def main():
async with httpx.AsyncClient() as client:
logfire.instrument_httpx(client)
await client.get(url)
asyncio.run(main())
logfire.instrument_httpx()
uses the
OpenTelemetry HTTPX Instrumentation package,
which you can find more information about here.