Giter Site home page Giter Site logo

aiohttp-sentry's Introduction

aiohttp-sentry

CI Status

An aiohttp server middleware for reporting failed requests to Sentry

Usage

Just add SentryMiddleware as a middleware:

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:

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:

Warning

This modifies your logging configuration globally when you instantiate the middleware. Even if you don't end up using the middleware instance for a request, all your logs will be sent to Sentry.

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:

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.

aiohttp-sentry's People

Contributors

alwxsin avatar f1ashhimself avatar jendagroovy avatar maroshmka avatar o3o3o avatar pbasista avatar playpauseandstop avatar underyx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

aiohttp-sentry's Issues

Error on scheme access

Hi, thanks for your library.

I encountered a bug when my ws connection closed. If my app tries to write into closed connection concurrent.futures._base.CancelledError raised. And this is ok.
But then aiohttp-sentry doesn't send an error to sentry because of

Traceback (most recent call last):
  ......
  File "/usr/local/lib/python3.6/site-packages/aiohttp_sentry/__init__.py", line 27, in middleware
    extra_data = await self.get_extra_data(request)
  File "/usr/local/lib/python3.6/site-packages/aiohttp_sentry/__init__.py", line 39, in get_extra_data
    'scheme': request.scheme,
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_request.py", line 290, in scheme
    if self.transport.get_extra_info('sslcontext'):
AttributeError: 'NoneType' object has no attribute 'get_extra_info'

I found the related issue but it seems closed.

Would you mind me create PR where I move request.scheme under if request.transport statement?

Requirements update

Hi,
I would like to ask if it was possible to update the requirements file - the given versions are outdated and produce following notice in Sentry - "This event was reported with an old version of the python SDK."
Thanks :)

Ability to enable Sentry breadcrumbs

Hi there!

Thanks for simple, but useful middleware. And I'm interested, why you decided to complete disable breadcrumbs in Sentry client by setting enable_breadcrumbs to False in sentry_kwargs?

Maybe it is better to have it disabled by default, but still be able to overwritten by user, like,

    def __init__(self, sentry_kwargs=None):
        if sentry_kwargs is None:
            sentry_kwargs = {}

       
        sentry_kwargs = {
            'transport': raven_aiohttp.AioHttpTransport,
            **sentry_kwargs,
        }
        sentry_kwargs.setdefault('enable_breadcrumbs', False)
        self.client = raven.Client(**sentry_kwargs)

?

New style of middleware

New style of middleware aio-libs/aiohttp#2252

I received following warning:

/usr/local/lib/python3.7/site-packages/aiohttp/web_app.py:165: DeprecationWarning:
old-style middleware "<aiohttp_sentry.SentryMiddleware object at 0x7f723aadf2b0>" deprecated, see #2252

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.