Skip to main content
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.

Metadata

Release files for aiohttp-sentry 0.4.0.post1

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.4.0.post1
File Size Uploaded
aiohttp-sentry-0.4.0.post1.tar.gz 3.0 kB Details

Built distribution (wheel)

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

Total release size: 6.0 kB

Release files / aiohttp-sentry-0.4.0.post1.tar.gz

Download URL aiohttp-sentry-0.4.0.post1.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
54d0ef7a9083d7eccf0feef3a41a806ea6d6397bef5f13dcdbdf81136b43f64b
BLAKE2b-256 checksum
How to use checksums
99e4746cbd4192f89604ff969c0a74d26bf8040545b4b6529e5b0d5bcc7dde68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / aiohttp_sentry-0.4.0.post1-py2.py3-none-any.whl

Download URL aiohttp_sentry-0.4.0.post1-py2.py3-none-any.whl
Size 3.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
350d57132d867e81d042b85c1bd2b2f48af8e08ed1c0de8d44a8fb6a90be272c
BLAKE2b-256 checksum
How to use checksums
f94ca83eb93d30665a3c2d13ca86cd956b19822935806e5953041157146b6ef1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.6.0

2 release files

0.5.0

2 release files

0.4.1

2 release files

This release

0.4.0.post1 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

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