HTTPX的¶
logfire.instrument_httpx()
方法可用于使用 Logfire 检测 HTTPX。
安装¶
使用 httpx
extra 安装 logfire
:
pip install 'logfire[httpx]'
rye add logfire -E httpx
poetry add 'logfire[httpx]'
用法¶
让我们看下面一个最小的例子。您可以使用 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()
使用 OpenTelemetry HTTPX Instrumentation 包,您可以在此处找到有关该包的更多信息。
本文总阅读量次