# AIOHTTP Client | Sentry for Python

The [AIOHTTP](https://docs.aiohttp.org/en/stable.md) integration instruments outgoing HTTP requests using the AIOHTTP client.

Use this integration to create spans for outgoing requests and ensure traces are properly propagated to downstream services.

This integration also supports AIOHTTP servers. See [AIOHTTP server documentation](https://docs.sentry.io/platforms/python/integrations/aiohttp.md) for details.

## [Install](https://docs.sentry.io/.md#install)

Install `sentry-sdk` from PyPI with the `aiohttp` extra.

```bash
pip install "sentry-sdk[aiohttp]"
```

## [Configure](https://docs.sentry.io/.md#configure)

If you have the `aiohttp` package in your dependencies, the AIOHTTP integration will be enabled automatically when you initialize the Sentry SDK.

Error Monitoring\[ ]Tracing\[ ]Profiling\[ ]Logs (Beta)

```python
import sentry_sdk

sentry_sdk.init(
    dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
    # Add data like request headers and IP for users, if applicable;
    # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
    send_default_pii=True,
    #  performance
    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for tracing.
    traces_sample_rate=1.0,
    #  performance
    #  profiling
    # To collect profiles for all profile sessions,
    # set `profile_session_sample_rate` to 1.0.
    profile_session_sample_rate=1.0,
    # Profiles will be automatically collected while
    # there is an active span.
    profile_lifecycle="trace",
    #  profiling
    #  logs

    # Enable logs to be sent to Sentry
    _experiments={
        "enable_logs": True,
    },
    #  logs
)
```

## [Verify](https://docs.sentry.io/.md#verify)

```python
import asyncio
import aiohttp

async def main():
    sentry_sdk.init(...)  # same as above

    with sentry_sdk.start_transaction(name="testing_sentry"):
        async with aiohttp.ClientSession() as session:
            async with session.get("https://sentry.io/") as response:
                print("Status:", response.status)
            async with session.post("http://httpbin.org/post") as response:
                print("Status:", response.status)

asyncio.run(main())
```

This will create a transaction called `testing_sentry` in the Performance section of [sentry.io](https://sentry.io/.md) and will create spans for the outgoing HTTP requests.

It takes a couple of moments for the data to appear in [sentry.io](https://sentry.io/.md).

## [Supported Versions](https://docs.sentry.io/.md#supported-versions)

* AIOHTTP: 3.5+
* Python: 3.7+
