Coder Social home page Coder Social logo

collective.sentry's Introduction

collective.sentry

Sentry integration with Zope.

Requirements

  • Plone 5.2, 5.1 (tested)
  • Python 3.6+, 2.7 (tested)

Installation

Add collective.sentry to your buildout and re-run buildout.

Configuration

Configure the Sentry DSN by setting the environment variable SENTRY_DSN inside your shell configuration or using buildout:

[instance]
environment-vars +=
    SENTRY_DSN https://......

Supplementary information logged in Sentry

collective.sentry will create automatically a Sentry tag instance_name which is derived from the buildout part name of the related instance. An additional tag project can be configured (optional) if you set the environment variable SENTRY_PROJECT. This allows you introduce an additional tag for filtering, if needed.

Set SENTRY_ENVIRONMENT to differentiate between environments e.g. staging vs production (https://docs.sentry.io/enriching-error-data/environments/)

Set SENTRY_RELEASE to sent release information to sentry. (https://docs.sentry.io/workflow/releases/)

Set ´SENTRY_INTEGRATIONS` (comma seperated) for different Integrations. (https://docs.sentry.io/platforms/python/configuration/integrations/)

Optional activation

By default, if you install collective.sentry along you eggs, the instance start will crash if you do not configure SENTRY_DSN. But sometime, you have multiple environments where you want that the product to be loaded, without doing anything under the hood (same conf for dev & prod, but no sentry on dev). To enable this behavior, add SENTRY_OPTIONAL=1 to your environment variables.

Repository

https://github.com/collective/collective.sentry

Licence

  • GPL2 - GNU Public License 2
  • based on raven.contrib.zope: BSD

Author

ZOPYX/Andreas Jung, [email protected]

collective.sentry has been developed as part of a Plone 5.2 migration project and it sponsored by the University Gent.

collective.sentry's People

Contributors

2silver avatar eikichi18 avatar folix-01 avatar fulv avatar gforcada avatar jensens avatar kiorky avatar krissik avatar lunga001 avatar mauritsvanrees avatar nimo-19 avatar thokas avatar thomasmassmann avatar zopyx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

collective.sentry's Issues

TypeError: get() got an unexpected keyword argument 'default' - SENTRY_MAX_LENGTH

When doing
bin/client1 fg
I get the error:

    __import__(moduleOrReq)
  File ".../buildout-cache/eggs/cp27mu/collective.sentry-0.3.1-py2.7.egg/collective/sentry/__init__.py", line 4, in <module>
    import collective.sentry.error_handler
  File ".../buildout-cache/eggs/cp27mu/collective.sentry-0.3.1-py2.7.egg/collective/sentry/error_handler.py", line 33, in <module>
    sentry_max_length = int(os.environ.get("SENTRY_MAX_LENGTH", default=512))
    zope.configuration.xmlconfig.ZopeXMLConfigurationError: File ".../buildout-cache/eggs/cp27mu/Products.CMFPlone-5.2.13- 
    py2.7.egg/Products/CMFPlone/meta.zcml", line 38.4-42.10
    File ".../zeocluster/parts/client1/etc/site.zcml", line 12.2-12.39
    TypeError: get() got an unexpected keyword argument 'default'

instancehome as base is insufficiant to tag instance_name

This works with one buildout creating several instances and run them on one machine.

It does not work:

  • same buildout on several severs
  • with docker images

code see

configuration = getConfiguration()
tags = {}
instancehome = configuration.instancehome
tags["instance_name"] = instancehome.rsplit(os.path.sep, 1)[-1]

This probably needs some conceptual work to get this right.
I consider this as a bug with low importance.

Grouping of errors

We are testing collective.senty.
On our old sentry server (8.9) every error created a new issue and on our new sentry (10.1.0.dev0) all
errors are grouped into one issue. Both is not very helpfull.

Did we miss a configuration option?

Integration with zeo server?

Thanks for this plugin! 🙇🏾

I'm wondering if one can integrate it on the ZEO server as well, on python 2 and with raven (the former python plugin for sentry) one could plug it in on the zeo-custom-log option from plone.recipe.zeoserver.

How one is meant to get tracebacks from the ZEO server to sentry with collective.sentry now? 🤔

collective.sentry still logs ignored Exceptions

Note for self as well, still have to dig/debug further. After upgrading to collective.sentry 0.2.3 I still get NotFound and Unauhorized tracebacks sent to sentry from Plone Plone 5.2.1/5.2.2 project, in spite of 85c85a6

Needs more investigation

unfiltered exceptions

Latest release

Hi @zopyx @thomasmassmann @gforcada
The latest addition to this add-on (SENTRY_DISABLE) can be very useful in several situations.
It would be awesome to have it released, is it possible?
Thank you kindly ☺️

request.stdin stream manipulation breaks when used under gunicorn

_get_request_from_request(request):¹ tries to do:

    body_pos = request.stdin.tell()
    request.stdin.seek(0)
    body = request.stdin.read()
    request.stdin.seek(body_pos)

However, it seems like under gunicorn this request.stdin doesn't have the tell method. (nor the seek method)²
Given that neither body_pos nor body seem to be used in that method, I'd suggest removing those 4 lines to make this code compatible with gunicorn. (or somehow check if tell is available)

¹ https://github.com/collective/collective.sentry/blob/master/collective/sentry/error_handler.py#L90-L93
¹ https://github.com/benoitc/gunicorn/blob/master/gunicorn/http/body.py#L177

New release

Hi,

can we make a new release of collective.sentry ?

Thanks

Error handling on Zope root is broken

Hi, in current release the error handling for sentry does seem broken on Zope root. I see an plone.api.exc.CannotGetPortalError exception when an error occurred on Zope root, e.g. /manage which would raises an Unauthorized error. This possible prevents Sentry from receiving any error which happens on Zope root and prevents me from login to ZMI.

Steps to reproduce:

  1. Install fresh Plone 5.2.1 with collective.sentry 0.2.2
  2. Clear browser cache and log out if needed.
  3. Go to http://localhost:8000/manage
  4. (Alternative try to produce an IPubFailure by calling any non existing or private content like http://localhost:8000/foo.bar)

Expected result:
Should show the ZMI of Zope root

Actual result:
Raises CannotGetPortalError from Plone API.

Full Stacktrace:
2020-07-17 11:42:17,633 ERROR   [waitress:357][waitress] Exception while serving /manage
Traceback (most recent call last):
File "/home/liebischer/Plone/eggs/Zope-4.1.3-py3.6.egg/ZPublisher/WSGIPublisher.py", line 156, in transaction_pubevents
  yield
File "/home/liebischer/Plone/eggs/Zope-4.1.3-py3.6.egg/ZPublisher/WSGIPublisher.py", line 338, in publish_module
  response = _publish(request, new_mod_info)
File "/home/liebischer/Plone/eggs/Zope-4.1.3-py3.6.egg/ZPublisher/WSGIPublisher.py", line 244, in publish
  obj = request.traverse(path, validated_hook=validate_user)
File "/home/liebischer/Plone/eggs/Zope-4.1.3-py3.6.egg/ZPublisher/BaseRequest.py", line 649, in traverse
  response.unauthorized()
File "/home/liebischer/Plone/eggs/Zope-4.1.3-py3.6.egg/ZPublisher/HTTPResponse.py", line 1027, in unauthorized
  raise exc
zExceptions.unauthorized.Unauthorized: You are not authorized to access this resource.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/liebischer/Plone/eggs/waitress-1.4.2-py3.6.egg/waitress/channel.py", line 349, in service
  task.service()
File "/home/liebischer/Plone/eggs/waitress-1.4.2-py3.6.egg/waitress/task.py", line 169, in service
  self.execute()
File "/home/liebischer/Plone/eggs/waitress-1.4.2-py3.6.egg/waitress/task.py", line 439, in execute
  app_iter = self.channel.server.application(environ, start_response)
File "/home/liebischer/Plone/eggs/Paste-3.1.1-py3.6.egg/paste/translogger.py", line 69, in __call__
  return self.application(environ, replacement_start_response)
File "/home/liebischer/Plone/eggs/Zope-4.1.3-py3.6.egg/ZPublisher/httpexceptions.py", line 30, in __call__
  return self.application(environ, start_response)
File "/home/liebischer/Plone/eggs/Zope-4.1.3-py3.6.egg/ZPublisher/WSGIPublisher.py", line 343, in publish_module
  environ['REMOTE_USER'] = user.getUserName()
File "/usr/lib/python3.6/contextlib.py", line 99, in __exit__
  self.gen.throw(type, value, traceback)
File "/home/liebischer/Plone/eggs/Zope-4.1.3-py3.6.egg/ZPublisher/WSGIPublisher.py", line 210, in transaction_pubevents
  notify(pubevents.PubFailure(request, exc_info, retry))
File "/home/liebischer/Plone/eggs/zope.event-4.4-py3.6.egg/zope/event/__init__.py", line 32, in notify
  subscriber(event)
File "/home/liebischer/Plone/eggs/zope.component-4.5-py3.6.egg/zope/component/event.py", line 27, in dispatch
  component_subscribers(event, None)
File "/home/liebischer/Plone/eggs/zope.component-4.5-py3.6.egg/zope/component/_api.py", line 124, in subscribers
  return sitemanager.subscribers(objects, interface)
File "/home/liebischer/Plone/eggs/zope.interface-4.6.0-py3.6-linux-x86_64.egg/zope/interface/registry.py", line 442, in subscribers
  return self.adapters.subscribers(objects, provided)
File "/home/liebischer/Plone/eggs/zope.interface-4.6.0-py3.6-linux-x86_64.egg/zope/interface/adapter.py", line 607, in subscribers
  subscription(*objects)
File "/home/liebischer/Plone/eggs/collective.sentry-0.2.2-py3.6.egg/collective/sentry/error_handler.py", line 189, in errorRaisedSubscriber
  error_log = api.portal.get_tool(name="error_log")
File "</home/liebischer/Plone/eggs/decorator-4.4.1-py3.6.egg/decorator.py:decorator-gen-2>", line 2, in get_tool
File "/home/liebischer/Plone/eggs/plone.api-1.10.0-py3.6.egg/plone/api/validation.py", line 77, in wrapped
  return function(*args, **kwargs)
File "/home/liebischer/Plone/eggs/plone.api-1.10.0-py3.6.egg/plone/api/portal.py", line 118, in get_tool
  return getToolByName(get(), name)
File "/home/liebischer/Plone/eggs/plone.api-1.10.0-py3.6.egg/plone/api/portal.py", line 82, in get
  'Unable to get the portal object. More info on '
plone.api.exc.CannotGetPortalError: Unable to get the portal object. More info on http://docs.plone.org/develop/plone.api/docs/api/exceptions.html#plone.api.exc.CannotGetPortalError

My troubleshooting results so far:
The issue seems related to merge request #8 which introduce an new check to ignored specific exceptions defined in error_log tool, but Plone API can't not determine the portal to get the correct tool from if the requested object is not within a Plone Portal. The error does not occur in collective.sentry 0.2.1.

Possible fix:

error_log = api.portal.get_tool(name="error_log")
Get the error_log tool from current portal or from zope app. For more details see findContext() from plone.app.theming (https://github.com/plone/plone.app.theming/blob/39dcb15feba2e70c8233c8d230efdd3eee286315/src/plone/app/theming/utils.py#L188). If it fails to get the tool, then the ignore check for exceptions should be skipped.

Example:

from Products.CMFCore.utils import getToolByName
from plone.app.theming.utils import findContext

try:
    from zope.component.hooks import getSite
except ImportError:
    from zope.app.component.hooks import getSite
..

@adapter(IPubFailure)
def errorRaisedSubscriber(event):
    
    try:
        context = findContext(event.request)
        error_log = getToolByName(context, name="error_log")
        if sys.exc_info()[0].__name__ in error_log._ignored_exceptions:
            return
    except AttributeError:
        pass

    with sentry_sdk.push_scope() as scope:
..

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.