class: center, middle  ## [Arthur Vuillard](mailto:arthur@hashbang.fr) Python Meetup Grenoble 26/02/2015 --- # Sentry ? > Sentry vous donne une idée des erreurs qui affectent vos utilisateurs. --- # Sentry ? - permet d'assurer un suivi des erreurs - proactivité - [pas juste un service en ligne](https://github.com/getsentry/sentry) --- background-image: url(it-works-everywhere-small.png) background-position: center; background-repeat: no-repeat; background-size: contain; --- # Sentry : sous le capot - Base de données relationnelle (MariaDB ou PostgreSQL) - serveur clef/valeur (Redis, optionnel, recommandé) - Python 2 seulement :( - Django - Celery --- # Quickstart ```bash virtualenv2 sentry source sentry/bin/activate pip install sentry[postgres] createdb sentry ``` --- # Quickstart ```bash sentry init vim ~/.sentry/sentry.conf.py sentry upgrade sentry createsuperuser sentry start # goto http://localhost:9000 ``` --- background-image: url(01_login.png) background-position: center; background-repeat: no-repeat; background-size: contain; --- background-image: url(02_new_team.png) background-position: center; background-repeat: no-repeat; background-size: contain; --- background-image: url(03_new_project.png) background-position: center; background-repeat: no-repeat; background-size: contain; --- background-image: url(04_flux.png) background-position: center; background-repeat: no-repeat; background-size: contain; --- background-image: url(05_error.png) background-position: center; background-repeat: no-repeat; background-size: contain; --- # Intégration appli Django ```bash ## dans l'environnement de l'appli pip install raven ``` --- # Intégration appli Django Dans le fichier settings.py : ```python # Définissez la valeur du DSN : RAVEN_CONFIG = { 'dsn': 'http://a7:c9@localhost/2', } # Ajoutez raven à la liste des # applications installées INSTALLED_APPS = INSTALLED_APPS + ( 'raven.contrib.django.raven_compat', ) ``` --- # Intégration appli Django - test de bon fonctionnement ```bash python manage.py raven test ``` - toutes les erreurs non capturées seront envoyées dans Sentry --- # Intégration appli Python - possibilité de logger des informations spécifiques avec le module logging ```python logger.error( 'There was some crazy error', exc_info=True, extra={'request': request} ) ``` --- # Intégration appli Python ```ini [loggers] keys=root [handlers] keys=console,sentry [formatters] keys=simple [logger_root] level=INFO handlers=sentry,console ``` --- # Intégration appli Python ```ini [formatter_simple] format=%(asctime)s - %(name)s - %(levelname)s - %(message)s datefmt= [handler_console] class=logging.StreamHandler level=INFO args=(sys.stdout,) [handler_sentry] class=raven.handlers.logging.SentryHandler level=WARNING args=('http://813:49@localhost/2',) ``` --- # Intégration appli Python ```python import logging import logging.config logging.config.fileConfig('logging.conf') logging.error('test error') logging.warning('test warning') logging.info('test info') ``` --- # Intégration appli Python ```python try: 1 / 0 except ZeroDivisionError: logging.exception( "A weird error occured" ) ``` --- # Intégration appli Python ```bash $ python app.py test error test warning test info Sentry is attempting to send 2 pending error messages Waiting up to 10 seconds Press Ctrl-C to quit $ ``` --- background-image: url(06_with_errors.png) background-position: center; background-repeat: no-repeat; background-size: contain; --- background-image: url(07_error_detail_1.png) background-position: center; background-repeat: no-repeat; background-size: contain; --- background-image: url(08_error_detail_2.png) background-position: center; background-repeat: no-repeat; background-size: contain; --- background-image: url(09_error_detail_3.png) background-position: center; background-repeat: no-repeat; background-size: contain; --- # Conclusion Pour aller plus loin : - [http://sentry.readthedocs.org/en/latest/](http://sentry.readthedocs.org/en/latest/) - [http://raven.readthedocs.org/en/latest/](http://raven.readthedocs.org/en/latest/) - [https://hashbang.fr/mise_a_jour_sentry.html](https://hashbang.fr/mise_a_jour_sentry.html) # Des questions ? ## .center[[arthur@hashbang.fr](mailto:arthur@hashbang.fr)]