Simple and Extensible Error Monitoring/Tracking framework for Python
Project description
Full featured error tracking module for Python apps supports Flask and Django
Introduction
ErrorTracker is a batteries-included app and extensions for python app, that can track errors, send notification, mask sensitive data and capture frames data.
It plays nicely with Django and Flask
Simple to use extension that lets you add error recording interfaces to Python applications. It’s implemented in such a way that the developer has total control of the resulting application.
Out-of-the-box, Error Tracker plays nicely with various ORM’s, including
It also boasts a simple Model management interface.
The biggest feature of ErrorTracker is flexibility. To start off with you can create a very simple application in no time, with exception monitor enabled, but then you can go further and customize different aspects.
ErrorTracker is an active project, well-tested and production ready.
Installation
To install ErrorTracker, simply:
pip install error-tracker
Features
Sensitive data( like password, secret ) Masking
Record all the frames ( frame data are stored in JSON format so that it can be analyzed later)
Unique URL generation
Number of times the exception occurred and first/last time of exception
Sending notifications with exception details
Record different types of exception like 500 or 404 etc
Raise or update ticket in Jira/Bugzilla etc by ticketing interface.
Usage
Flask App configuration
...
APP_ERROR_SEND_EMAIL = True
APP_ERROR_RECIPIENT_EMAIL = ('example@example.com',)
APP_ERROR_SUBJECT_PREFIX = "Server Error"
APP_ERROR_EMAIL_SENDER = 'user@example.com'
app.py
from flask import Flask
from flask_mail import Mail
import settings
from error_tracker import AppErrorTracker, NotificationMixin
from flask_sqlalchemy import SQLAlchemy
...
app = Flask(__name__)
app.config.from_object(settings)
db = SQLAlchemy(app)
class Notifier(Mail, NotificationMixin):
def notify(self, request, exception,
email_subject=None,
email_body=None,
from_email=None,
recipient_list=None):
message = Message(email_subject, recipient_list, email_body, sender=from_email)
self.send(message)
mailer = Notifier(app=app)
error_tracker = AppErrorTracker(app=app, db=db, notifier=mailer)
....
....
# Record exception when 404 error code is raised
@app.errorhandler(403)
def error_403(e):
error_tracker.capture_exception()
# any custom logic
# Record error using decorator
@app.errorhandler(500)
@error_tracker.track_exception
def error_500(e):
# some custom logic
....
Django App Usage
We need to update settings.py file as
Add app to installed apps list
Add Middleware for exception tracking. This should be added at the end so that it can process exception 1st in the middleware call stack.
Other configs related to notification
Sample Code
...
APP_ERROR_RECIPIENT_EMAIL = ('example@example.com',)
APP_ERROR_SUBJECT_PREFIX = "Server Error"
APP_ERROR_EMAIL_SENDER = 'user@example.com'
INSTALLED_APPS = [
...
'error_tracker.DjangoErrorTracker'
]
MIDDLEWARE = [
...
'error_tracker.django.middleware.ExceptionTrackerMiddleWare'
]
Documentations
This has got extensive document browse at https://error-tracker.readthedocs.io/en/latest/
All docs are in docs/source
And if you want to preview any .rst snippets that you may want to contribute, go to http://rst.ninjs.org/.
Examples
Several usage examples are included in the /tests folder. Please feel free to add your own examples, or improve on some of the existing ones, and then submit them via GitHub as a pull-request.
You can see some of these examples in action at https://github.com/sonus21/error-tracker/tree/master/examples To run the examples on your local environment, one at a time, do something like:
cd error-tracker/examples
Django:
cd error-tracker/examples cd DjangoSample python manage.py runserver
Flask:
cd flask-sample python app.py
Tests
To run the tests, from the project directory, simply:
pip install -r requirements-dev.txt bash run-tests.sh
You should see output similar to:
............................................. ---------------------------------------------------------------------- Ran 31 tests in 1.144s OK
Contribution
You’re most welcome to raise pull request or fixes.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file error-tracker-3.1.1.tar.gz
.
File metadata
- Download URL: error-tracker-3.1.1.tar.gz
- Upload date:
- Size: 29.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f0736183441f99ede82f94eb100f39065068ae83bf8255ac5e4828a2ea64542 |
|
MD5 | 2a1dc1a2118c94f6d593139208b8fd39 |
|
BLAKE2b-256 | 437586bc90a9f27039b6c5d11531676e898c673be0bbc6160189c61103b57146 |