Skip to content

Sample django app - Make log events from structlog similar to log events from logging for Sentry

License

Notifications You must be signed in to change notification settings

chiragjn/sentry_structlog_experiments

Repository files navigation

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+

  1. Install requirements (preferrably in a virtual environment)

    pip install -r requirements.txt
  2. Sign up for sentry, create a project and get a DSN

  3. Copy .env.template to .env

    cp .env.template .env
  4. Edit .env with your favorite editor and paste your Sentry DSN

    SENTRY_DSN=https://{...}@{...}.ingest.sentry.io/{...}
    
  5. Run the dev server

    python manage.py runserver 0.0.0.0:8000
  6. Go create errors

  7. Go explore the code at setup_logs and setup_sentry

About

Sample django app - Make log events from structlog similar to log events from logging for Sentry

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages