AIOHTTP

The AIOHTTP integration adds support for the AIOHTTP-Server Web Framework.

If you use AIOHTTP as your HTTP client and want to instrument outgoing HTTP requests have a look at the AIOHTTP Client documentation.

Install sentry-sdk from PyPI with the aiohttp extra:

Copied
pip install --upgrade sentry-sdk[aiohttp]

If you're on Python 3.6, you also need the aiocontextvars package:

Copied
pip install --upgrade aiocontextvars

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

Copied
import sentry_sdk

sentry_sdk.init(
    dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
    enable_tracing=True
)

Copied
from aiohttp import web

sentry_sdk.init(...)  # same as above

async def hello(request):
    1/0  # raises an error
    return web.Response(text="Hello, world")

app = web.Application()
app.add_routes([web.get('/', hello)])

web.run_app(app)

When you point your browser to http://localhost:8080/ a transaction will be created in the Performance section of sentry.io. Additionally, an error event will be sent to sentry.io and will be connected to the transaction.

It takes a couple of moments for the data to appear in sentry.io.

  • The Sentry Python SDK will install the AIOHTTP integration for all of your apps.
  • All exceptions leading to an Internal Server Error are reported.
  • The AIOHTTP integration currently does not attach the request body, see GitHub issue.
  • Logging with any logger will create breadcrumbs when the Logging integration is enabled (done by default).

By adding AioHttpIntegration to your sentry_sdk.init() call explicitly, you can set options for AioHttpIntegration to change its behavior:

Copied
import sentry_sdk
from sentry_sdk.integrations.aiohttp import AioHttpIntegration

sentry_sdk.init(
    dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
    enable_tracing=True,
    integrations=[
        AioHttpIntegration(
            transaction_style="method_and_path_pattern",
        ),
    ],
)

You can pass the following keyword arguments to AioHttpIntegration():

Configure the way Sentry names transactions:

  • GET /path/{id} if you set transaction_style="method_and_path_pattern"
  • <module_name>.hello if you set transaction_style="handler_name"

The default is "handler_name".

  • AIOHTTP: 3.5+
  • Python: 3.7+
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").