-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from plone/wsgi_sentry_support
Add Sentry support
- Loading branch information
Showing
6 changed files
with
184 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add Sentry support by adding a new filter to the WSGI pipeline. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import logging | ||
import sentry_sdk | ||
from sentry_sdk.integrations.logging import LoggingIntegration, ignore_logger | ||
|
||
|
||
def sdk_init( | ||
global_conf, | ||
dsn, | ||
level='INFO', | ||
event_level='ERROR', | ||
ignorelist=''): | ||
sentry_logging = LoggingIntegration( | ||
level=logging.__dict__[level], | ||
event_level=logging.__dict__[event_level] | ||
) | ||
for logger in ignorelist.split(): | ||
ignore_logger(logger) | ||
|
||
def filter(app): | ||
sentry_sdk.init(dsn=dsn, integrations=[sentry_logging]) | ||
return app | ||
return filter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,7 @@ The buildout has also created an INI file containing the waitress configuration: | |
[filter:translogger] | ||
use = egg:Paste#translogger | ||
setup_console_handler = False | ||
<BLANKLINE> | ||
... | ||
[pipeline:main] | ||
pipeline = | ||
translogger | ||
|
@@ -372,3 +372,112 @@ The buildout has updated our INI file: | |
handlers = | ||
qualname = waitress | ||
... | ||
|
||
Sentry support | ||
============== | ||
|
||
We want to sent logging events to Sentry. | ||
Let's create a buildout: | ||
|
||
>>> write('buildout.cfg', | ||
... ''' | ||
... [buildout] | ||
... parts = instance | ||
... find-links = %(sample_buildout)s/eggs | ||
... | ||
... [instance] | ||
... recipe = plone.recipe.zope2instance | ||
... eggs = | ||
... plone.recipe.zope2instance[sentry] | ||
... user = me:me | ||
... sentry_dsn = https://[email protected]/9999 | ||
... ''' % options) | ||
|
||
Let's run it:: | ||
|
||
>>> print(system(join('bin', 'buildout'))), | ||
Uninstalling instance. | ||
Installing instance. | ||
Getting distribution for 'sentry-sdk'. | ||
... | ||
Generated script '.../sample-buildout/bin/instance'. | ||
... | ||
|
||
The buildout has updated our INI file: | ||
|
||
>>> instance = os.path.join(sample_buildout, 'parts', 'instance') | ||
>>> wsgi_ini = open(os.path.join(instance, 'etc', 'wsgi.ini')).read() | ||
>>> print(wsgi_ini) | ||
[server:main] | ||
paste.server_factory = plone.recipe.zope2instance:main | ||
use = egg:plone.recipe.zope2instance#main | ||
... | ||
[filter:sentry] | ||
use = egg:plone.recipe.zope2instance#sentry | ||
dsn = https://[email protected]/9999 | ||
level = INFO | ||
event_level = ERROR | ||
ignorelist = | ||
<BLANKLINE> | ||
[pipeline:main] | ||
pipeline = | ||
translogger | ||
egg:Zope#httpexceptions | ||
sentry | ||
zope | ||
<BLANKLINE> | ||
[loggers] | ||
... | ||
|
||
Let's update our buildout with some Sentry options: | ||
|
||
>>> write('buildout.cfg', | ||
... ''' | ||
... [buildout] | ||
... parts = instance | ||
... find-links = %(sample_buildout)s/eggs | ||
... | ||
... [instance] | ||
... recipe = plone.recipe.zope2instance | ||
... eggs = | ||
... plone.recipe.zope2instance[sentry] | ||
... user = me:me | ||
... sentry_dsn = https://[email protected]/9999 | ||
... sentry_level = DEBUG | ||
... sentry_event_level = WARNING | ||
... sentry_ignore = waitress.queue foo | ||
... ''' % options) | ||
|
||
Let's run it:: | ||
|
||
>>> print(system(join('bin', 'buildout'))), | ||
Uninstalling instance. | ||
Installing instance. | ||
Generated script '.../sample-buildout/bin/instance'. | ||
... | ||
|
||
The buildout has updated our INI file: | ||
|
||
>>> instance = os.path.join(sample_buildout, 'parts', 'instance') | ||
>>> wsgi_ini = open(os.path.join(instance, 'etc', 'wsgi.ini')).read() | ||
>>> print(wsgi_ini) | ||
[server:main] | ||
paste.server_factory = plone.recipe.zope2instance:main | ||
use = egg:plone.recipe.zope2instance#main | ||
... | ||
[filter:sentry] | ||
use = egg:plone.recipe.zope2instance#sentry | ||
dsn = https://[email protected]/9999 | ||
level = DEBUG | ||
event_level = WARNING | ||
ignorelist = waitress.queue foo | ||
<BLANKLINE> | ||
[pipeline:main] | ||
pipeline = | ||
translogger | ||
egg:Zope#httpexceptions | ||
sentry | ||
zope | ||
<BLANKLINE> | ||
[loggers] | ||
... |