An aiohttp middleware for reporting errors to Sentry
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file aiohttp-sentry-0.4.1.tar.gz
.
File metadata
- Download URL: aiohttp-sentry-0.4.1.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcaac444b5b79e62be918015ef8c8f60859ea285bd377462f63c0084d668684e |
|
MD5 | 3b3fb7819135fe7511c1d9bac7a68d50 |
|
BLAKE2b-256 | 86b827f60fb1524e6f1afa83e411bed41e3a2daf574e6bb14f8df45e01cc6d61 |
File details
Details for the file aiohttp_sentry-0.4.1-py2.py3-none-any.whl
.
File metadata
- Download URL: aiohttp_sentry-0.4.1-py2.py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0749df462027745c6b9705f31e22e0b6894c68bdf2d757067a48a16215ac8838 |
|
MD5 | b208938a964504698a5ff330c6cf5878 |
|
BLAKE2b-256 | 16d0841bd3f127c3dd16db9335dcc27fb02d56709b6969244b2d5d6c75acbb37 |