AIOHTTP

The AIOHTTP integration adds support for the AIOHTTP-Server Web Framework. A Python version of 3.6 or greater is required.

Install

Install sentry-sdk from PyPI:

Copied
pip install --upgrade sentry-sdk

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

Copied
pip install --upgrade aiocontextvars

Configure

Copied
import sentry_sdk
from sentry_sdk.integrations.aiohttp import AioHttpIntegration

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

    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for performance monitoring.
    # We recommend adjusting this value in production,
    traces_sample_rate=1.0,
)

from aiohttp import web

async def hello(request):
      return web.Response(text="Hello, world")

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

web.run_app(app)

Behavior

  • 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 the relevant GitHub issue.

  • Logging with any logger will create breadcrumbs when the Logging integration is enabled (done by default).

Options

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

  • transaction_style:

    Copied
    app.router.add_get(r'/path/{id}', hello)

    For transactions generated by the above code, you can set the transaction name to:

    • 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".

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").