django-celery-errorlog
Reuseable app for django to collect the unexpted exception and generate comprehansive report just like what you get in debug mode and store in database from celery task
Introduction
This is a extension of django-errorlog to bring support of celery task with some other features. I love Celery, but sometimes when there are bugs hiding in the celery tasks code, and the code has already running as deamon in the background of the production server, you will find it’s hard to track and debug the error. More importantly, when a unhandled exception happened, that’s also means the task failed, and the arguments send to this task will be losed. To solve this problem, this app wrap you task function inside a database transaction, when unhandled exception been catched by the wrapper, it will do this following stuff:
rollback this transaction
get the exception and traceback to generate a HTML error report as same as the Django buildin 500 page when DEBUG=True, which contains the stack trace also the varibles in each stack. That make it much easier to debug.
record the arguments of this task
get the error categorized
So, after error happened, you can check the CeleryError.unfixed_errors, then fix the code, restart the worker, then run error.fix() to send this task back to the queue again to make sure all task will be run.
If you do error.fix() before you fixed code in place, it’s doesn’t matter, because even the old error has been mark as fixed, since the same error will be raised again, so you will get new error with same parameters.
Change Logs
2016-12-04: 0.1.0 Initial submit. Split the code from the online project. Write the documents, and add the tests.
Install
pip install django-celery-errorlog
Then modify the settings
Follow the instruction of django-errorlog to set it up properly
set up djcelery properly
Add djcelery-errorlog into INSTALLED_APPS after errorlog
Then do python manage.py migrate to setup the database table.
Usage
In tasks.py, you have to change the import of shared_task and periodic_task from celery to djcelery_errorlog to make errorlog work, here is the example
# -*- coding: utf-8 -*-
from djcelery_errorlog import shared_task
@shared_task(name="tests")
def tests(**kwargs):
raise ValueError(kwargs)
That’s it, now when there is uncatched exception been throwed, CeleryError will record the invoke parameter and stack trace.
buildin shell command(same as django-errorlog)
>>> from djcelery_errorlog.models import CeleryError
>>> CeleryError.unfixed_errors
{0: <CeleryError: 1 - test1 - ValueError: A>,
1: <CeleryError: 4 - test2 - ValueError: B>}
>>> error = CeleryError.unfixed_errors[1]
>>> error
1: <CeleryError: 4 - test1 - ValueError: B>
>>> # in this repr, the first number is the index to make it easy to select;
>>> # the second number 4 is the the count of the same error happened;
>>> # test1 is the name of the task;
>>> # ValueError is the exception type;
>>> # B is the args in the exception.
>>> error.vcs_rev # the git/hg version of error, for hg, it's the incremental number that is orderable
"1"
>>> error.ignore() # this command ignore the whole 4 error logs
Fix the error
After you fixed the code base on the error been tracked, you can do error.fix([queue="queue_name"]) to get the task with same parameter run again. Remember, when you run fix on one error, all same errors will be send to the celery worker and marked as fixed.
Metadata
Release files for django-celery-errorlog 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-celery-errorlog-0.1.1.tar.gz | 4.9 kB | Without provenance | Details for django-celery-errorlog-0.1.1.tar.gz |
Release files / django-celery-errorlog-0.1.1.tar.gz
| Download URL | django-celery-errorlog-0.1.1.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
28ebbca85089e31b802305207d2a5feb810d7af34cae4dfce02588dce5430ab8
|
|
BLAKE2b-256 checksum How to use checksums |
0ee794d7c5f8dea4d0621ad16ff700a4a0e1363c9b78abd9a9b49fdb6cb9623b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-celery-errorlog 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.