Skip to content

AIOHTTP Client

AIOHTTP is an asynchronous HTTP client/server framework for asyncio and Python.

logfire.instrument_aiohttp_client() Method creates a span for each request made by the AIO HTTP client.

Issue

"What about AIOHTTP server? AIOHTTP server instrumentation is not supported yet. You can here to track progress.

install

Install logfire using aiohttp extra:

{{ install_logfire(extras=['aiohttp']) }}

usage

Let's look at the smallest example below. You can use python main.py Run it:

main.py
import logfire
import aiohttp


logfire.configure()
logfire.instrument_aiohttp_client()


async def main():
    async with aiohttp.ClientSession() as session:
        await session.get("https://httpbin.org/get")


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Keyword arguments for logfire.instrument_aiohttp_client() are passed to the AioHttpClientInstrumentor().instrument() method of the OpenTelemetry aiohttp client Instrumentation package,Read more about it here.


本文总阅读量次