Skip to content

AIOHTTP Client

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

The logfire.instrument_aiohttp_client() method will create a span for every request made by your AIOHTTP clients.

What about AIOHTTP Server?

The AIOHTTP server instrumentation is not supported yet. You can track the progress here.

Installation

Install logfire with the aiohttp extra:

pip install 'logfire[aiohttp]'
rye add logfire -E aiohttp
poetry add 'logfire[aiohttp]'

Usage

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

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())

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