Skip to content

websauna/websauna.sentry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a Python package for websauna.sentry addon for Websauna framework.

Features

  • Extra logging context like user email and country
  • Internally uses pyramid_raven.

https://raw.githubusercontent.com/websauna/websauna.sentry/master/screenshots/user_context.png

Installation

Install package from PyPi.

We assume you have Sentry configured with self-signed certificates that the system cannot verify.

Note: When you create a new Pyramid project in Sentry. It gives you some sane settings to use below.

In your production.ini settings configure:

[app:main]
# ...

# This is where our internal server errors go.
# Exceptions are logged with extra user details.
raven.dsn = https://x:[email protected]:443/1?verify_ssl=0&timeout=30

#
# Sentry
#

# debugtoolbar may interfere with exception capturance
debugtoolbar.enabled = false

# Only use special internal server error capture,
# and do not post (twice) internal server errors to
# sentry through Python logging system.
# HOWEVER this means the exceptions do not appear in console/log files either.
websauna.log_internal_server_error = false

#
# Logger configuration
#

# Also add Sentry to normal Python logging configuration, so you catch
# warns and errors from loggers.
[handlers]
keys = console, sentry

# The root error capture
[logger_root]
level = DEBUG
handlers = console, sentry, logfile

[handler_sentry]
class = raven.handlers.logging.SentryHandler
args = ('https://x:[email protected]/2?verify_ssl=0&timeout=30',)
level = WARNING
formatter =

In your application Initializer do:

def include_addons(self):
    # ...
    self.config.include("websauna.sentry")

For Raven client options (URL parameters) see

Usage

Test in production by going to the Websauna internal error trigger URL:

http://yoursite.example.com/error-trigger

Or on local development:

http://localhost:6543/error-trigger

This will trigger test exception and logging messages you should see in Sentry.

Extra logging context

Examples:

import logging

from websauna.system.core.loggingcapture import get_logging_user_context

logger = logging.getLogger(__name__)

def my_view(request):
    # If you're actually catching an exception, use `exc_info=True`
    logger.error('There was an error, with a stacktrace!', exc_info=True)

    user_context = get_logging_user_context(request)
    logger.error("Logging message on error level", exc_info=True, extra={"user": user_context})

More information

Troubleshooting

Celery reflect issue:

[loggers]
keys = root, sqlalchemy, celery_worker_job, colander, notebook, authomatic, celery_redirected

# Raven logger creating log entries itself when celery does stdout capture -> infinite loop
# b'[\'b"[\\\'Could not acquire lock on testnet when doing update_networks \\\']" \']'
[logger_celery_redirected]
level = INFO
# No sentry
handlers = logfile
qualname = celery.redirected

More information

Please see https://websauna.org/

About

Sentry support add-on for Websauna

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published