A minimal Django app for running sentry along with structlog json logging setup
JSON structured messages make Sentry issues and breadcrumbs hard to read, but are great for parsing and aggregating in ELK stack. We do some hacking around with structlog and sentry internals to make them work together nicely
- Send plain text string log events instead of json/dict events to Sentry
- Send plain text string breadcrumb events instead of json/dict events to Sentry
- Save traceback to
LogRecord.exc_info
when using structlog so Sentry can extract it - Allow copying custom keys from event_dict to LogRecord attributes so Sentry can put it as extra (E.g. see
request_id
in the above screenshot) - Get
'_meta'
key in Sentry event json when using structlog
Other related projects that attempt to solve this problem:
To run (sorry no docker or uwsgi here):
Needs Python 3.6+
-
Install requirements (preferrably in a virtual environment)
pip install -r requirements.txt
-
Sign up for sentry, create a project and get a DSN
-
Copy
.env.template
to.env
cp .env.template .env
-
Edit
.env
with your favorite editor and paste your Sentry DSNSENTRY_DSN=https://{...}@{...}.ingest.sentry.io/{...}
-
Run the dev server
python manage.py runserver 0.0.0.0:8000
-
Go create errors
-
Go explore the code at setup_logs and setup_sentry