Skip to main content

aiohttp-sentry

CI Status

An aiohttp server middleware for reporting failed requests to Sentry

Usage

Just add SentryMiddleware as a middleware:

from aiohttp import web
from aiohttp_sentry import SentryMiddleware
app = web.Application(middlewares=[SentryMiddleware()])

Configuration

If you want to customize error reporting, you can use the optional sentry_kwargs parameter, which is a dict of kwargs passed to the lower-level Sentry library, raven. With this, you can specify environment details, filter out specific exceptions, and so on:

from aiohttp import web
from aiohttp_sentry import SentryMiddleware
app = web.Application(
    middlewares=(
        SentryMiddleware({
            'environment': 'foo',
            'release': 'bar',
            'ignore_exceptions': 'aiohttp.HTTPClientError'
        }),
        # ...
    ),
)

If you are using the standard library’s logging module, we have a convenient parameter to patch it for you, to have logger calls send events to Sentry automatically:

import logging
from aiohttp import web
from aiohttp_sentry import SentryMiddleware

app = web.Application(
    middlewares=[SentryMiddleware(patch_logging=True, sentry_log_level=logging.WARNING)],
)

Attaching Data to Events

By default, aiohttp-sentry passes this data alongside reported exceptions:

  • HTTP scheme

  • HTTP method

  • URL

  • Query String

  • Request Headers (including cookies)

  • Requester’s IP address

If you need more data in sentry, you can do that by subclassing from SentryMiddleware and overriding the get_extra_data method, which returns all the above by default. Here’s what that looks like:

class DetailedSentryMiddleware(SentryMiddleware):

    async def get_extra_data(self, request):
        return {
            **await super().get_extra_data(request),
            'settings': request.app['settings'],
        }

While get_extra_data is a coroutine, which means it can make database queries, API calls, or other I/O operations, use this carefully! Make sure you understand the implications of executing expensive operations every time an error happens. If the root cause of the error is an overloaded database, you are just going to make the problem worse, while not even being able to get the extra info you wanted.

Metadata

Release files for aiohttp-sentry 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiohttp-sentry 0.6.0
File Size Uploaded Provenance
aiohttp-sentry-0.6.0.tar.gz 3.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for aiohttp-sentry 0.6.0
File Interpreter ABI Platform
aiohttp_sentry-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.6 kB

Release files / aiohttp-sentry-0.6.0.tar.gz

Download URL aiohttp-sentry-0.6.0.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ea059c72553ae12f66bac020d4af98aa37399754b647f01258b5ec04f34d3bda
BLAKE2b-256 checksum
How to use checksums
7833b0053af4c7027e88606e8ff2498a7f4fe8c36397619bfcd07b5a20f5ffc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release files / aiohttp_sentry-0.6.0-py3-none-any.whl

Download URL aiohttp_sentry-0.6.0-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
05ef17aabc74c4c464a405e0a5c95f062f80ad0178d9cb2b5e613d0656741ea6
BLAKE2b-256 checksum
How to use checksums
bcfb05ebe534849733bf1d94cf6b51e3ec14c58e217e6a8f7ae95bb1a9cfd8ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Security for aiohttp-sentry 0.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page