Skip to main content

An aiohttp middleware for reporting errors to Sentry

Project description

CI Status

An aiohttp middleware for reporting errors to Sentry. Python 3.5+ is required.

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'
        }),
        # ...
    ),
)

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 {
            **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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiohttp-sentry-0.4.0.post1.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

aiohttp_sentry-0.4.0.post1-py2.py3-none-any.whl (3.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file aiohttp-sentry-0.4.0.post1.tar.gz.

File metadata

File hashes

Hashes for aiohttp-sentry-0.4.0.post1.tar.gz
Algorithm Hash digest
SHA256 54d0ef7a9083d7eccf0feef3a41a806ea6d6397bef5f13dcdbdf81136b43f64b
MD5 a015360b9edb98b24f4c5434f05e4fa8
BLAKE2b-256 99e4746cbd4192f89604ff969c0a74d26bf8040545b4b6529e5b0d5bcc7dde68

See more details on using hashes here.

File details

Details for the file aiohttp_sentry-0.4.0.post1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for aiohttp_sentry-0.4.0.post1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 350d57132d867e81d042b85c1bd2b2f48af8e08ed1c0de8d44a8fb6a90be272c
MD5 17742e221c0363fb930a2f2582f9da5d
BLAKE2b-256 f94ca83eb93d30665a3c2d13ca86cd956b19822935806e5953041157146b6ef1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page