Skip to content

Commit d1d29bf

Browse files
sonus21sonu-zomato
authored andcommitted
Re-wrote code to support Django as well flask and stand alone python.
1 parent f98b1cc commit d1d29bf

134 files changed

Lines changed: 4212 additions & 1251 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.coveragerc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[run]
2-
omit =
3-
*tests.py
2+
include = error_tracker/*
3+
omit = *migrations*, *tests*
44

55
[report]
66
exclude_lines =

.travis.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
language: python
22
sudo: false
3-
language: python
43
python:
54
- 2.7
5+
- 3.5
6+
- 3.6
7+
- 3.7
8+
- 3.8
69
cache: pip
710
install:
811
- pip install -r requirements-dev.txt
9-
- pip install coveralls
1012

1113
script:
12-
- coverage run --source flask_error setup.py test
14+
- coverage run tests/DjangoTest/runners/common_runner.py
15+
- coverage run -a tests/DjangoTest/runners/custom_masking_test_runner.py
16+
- coverage run -a tests/DjangoTest/runners/masking_disabled_test_runner.py
17+
- coverage run -a tests/DjangoTest/runners/model_test_runner.py
18+
- coverage run -a tests/DjangoTest/runners/notification_test_runner.py
19+
- coverage run -a tests/flask-test-runner.py
1320

1421
notifications:
1522
email:

LICENSE.rst

Lines changed: 0 additions & 25 deletions
This file was deleted.

LICENSE.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Copyright 2018 Sonu Kumar
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
1. Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
10+
2. Redistributions in binary form must reproduce the above copyright
11+
notice, this list of conditions and the following disclaimer in the
12+
documentation and/or other materials provided with the distribution.
13+
14+
3. Neither the name of the copyright holder nor the names of its
15+
contributors may be used to endorse or promote products derived from
16+
this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
21+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

MANIFEST.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include LICENSE.rst
1+
include LICENSE.txt
22
include README.rst
3-
recursive-include flask_error/templates *
4-
recursive-exclude flask_error *.pyc
3+
recursive-include error_tracker/* *
4+
recursive-exclude error_tracker *.pyc

README.rst

Lines changed: 124 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,144 @@
11
==============================
2-
Flask Error Monitor
2+
Error Tracker
33
==============================
44

5-
Full featured error monitor app for Flask
5+
Full featured error tracking module for Python apps supports Flask and Django
66

7-
.. image:: https://travis-ci.org/sonus21/flask-error-monitor.svg?branch=master
8-
:target: https://travis-ci.org/sonus21/flask-error-monitor
7+
.. image:: https://travis-ci.org/sonus21/error-tracker.svg?branch=master
8+
:target: https://travis-ci.org/sonus21/error-tracker
99

10-
.. image:: https://coveralls.io/repos/github/sonus21/flask-error-monitor/badge.svg
11-
:target: https://coveralls.io/github/sonus21/flask-error-monitor
10+
.. image:: https://coveralls.io/repos/github/sonus21/error-tracker/badge.svg
11+
:target: https://coveralls.io/github/sonus21/error-tracker
1212

1313
Introduction
1414
------------
15+
ErrorTracker is a batteries-included app and extensions for python app, that can track errors, send notification, mask sensitive data and capture frames data.
1516

16-
Flask-Error-Monitor is a batteries-included, simple-to-use `Flask <http://flask.pocoo.org/>`_ extension that lets you
17-
add error recording interfaces to Flask applications. It's implemented in such a way that the developer has total control of the resulting application.
17+
It plays nicely with `Django <https://www.djangoproject.com/>`_ and `Flask <http://flask.pocoo.org/>`_
1818

19-
Out-of-the-box, Flask-Error-Monitor plays nicely with various ORM's, including
19+
Simple to use extension that lets you add error recording interfaces to Python applications.
20+
It's implemented in such a way that the developer has total control of the resulting application.
2021

21-
- `SQLAlchemy <http://www.sqlalchemy.org/>`_,
22+
Out-of-the-box, Error Tracker plays nicely with various ORM's, including
2223

24+
- `SQLAlchemy <http://www.sqlalchemy.org/>`_,
2325
- `MongoEngine <http://mongoengine.org/>`_,
26+
- `Django ORM <https://tutorial.djangogirls.org/en/django_orm/>`_
2427

2528

2629
It also boasts a simple Model management interface.
2730

28-
The biggest feature of Flask-Error-Monitor is flexibility. To start off with you can create a very simple application in no time,
31+
The biggest feature of ErrorTracker is flexibility. To start off with you can create a very simple application in no time,
2932
with exception monitor enabled, but then you can go further and customize different aspects.
3033

31-
Flask-Error-Monitor is an active project, well-tested and production ready.
34+
ErrorTracker is an active project, well-tested and production ready.
3235

3336
Installation
3437
------------
35-
To install Flask-Error-Monitor, simply::
38+
To install ErrorTracker, simply::
3639

37-
git clone git@github.com:sonus21/flask-error-monitor.git
38-
cd flask-error-monitor
39-
python setup.py install
40+
pip install error-tracker
4041

4142

4243
Features
43-
-------------
44+
--------
4445
- Sensitive data( like *password*, *secret* ) Masking
4546
- Record all the frames ( frame data are stored in JSON format so that it can be analyzed later)
4647
- Unique URL generation
4748
- Number of times the exception occurred and first/last time of exception
48-
- Sending emails with exception details
49+
- Sending notifications with exception details
4950
- Record different types of exception like 500 or 404 etc
51+
- Raise or update ticket in Jira/Bugzilla etc by ticketing interface.
52+
53+
Usage
54+
-----
55+
56+
Flask App configuration
57+
=======================
58+
59+
.. code::
60+
61+
...
62+
APP_ERROR_SEND_EMAIL = True
63+
APP_ERROR_RECIPIENT_EMAIL = ('example@example.com',)
64+
APP_ERROR_SUBJECT_PREFIX = "Server Error"
65+
APP_ERROR_EMAIL_SENDER = 'user@example.com'
66+
67+
68+
69+
app.py
70+
71+
.. code::
72+
73+
from flask import Flask
74+
from flask_mail import Mail
75+
import settings
76+
from error_tracker import AppErrorTracker, NotificationMixin
77+
from flask_sqlalchemy import SQLAlchemy
78+
...
79+
app = Flask(__name__)
80+
app.config.from_object(settings)
81+
db = SQLAlchemy(app)
82+
class Notifier(Mail, NotificationMixin):
83+
def notify(self, request, exception,
84+
email_subject=None,
85+
email_body=None,
86+
from_email=None,
87+
recipient_list=None):
88+
message = Message(email_subject, recipient_list, email_body, sender=from_email)
89+
self.send(message)
90+
mailer = Notifier(app=app)
91+
error_tracker = AppErrorTracker(app=app, db=db, notifier=mailer)
92+
93+
....
94+
95+
....
96+
# Record exception when 404 error code is raised
97+
@app.errorhandler(403)
98+
def error_403(e):
99+
error_tracker.record_exception()
100+
# any custom logic
101+
102+
# Record error using decorator
103+
@app.errorhandler(500)
104+
@error_tracker.track_exception
105+
def error_500(e):
106+
# some custom logic
107+
....
108+
109+
110+
Django App Usage
111+
================
112+
113+
We need to update settings.py file as
114+
115+
- Add app to installed apps list
116+
- Add Middleware for exception tracking. This should be added at the end so that it can process exception 1st in the middleware call stack.
117+
- Other configs related to notification
118+
119+
Sample Code
120+
121+
122+
.. code::
123+
124+
...
125+
APP_ERROR_RECIPIENT_EMAIL = ('example@example.com',)
126+
APP_ERROR_SUBJECT_PREFIX = "Server Error"
127+
APP_ERROR_EMAIL_SENDER = 'user@example.com'
128+
129+
INSTALLED_APPS = [
130+
...
131+
'error_tracker.DjangoErrorTracker'
132+
]
133+
MIDDLEWARE = [
134+
...
135+
'error_tracker.django.middleware.ExceptionTrackerMiddleWare'
136+
]
137+
50138
51139
Documentations
52-
-------------
53-
This has got extensive document browse at https://flask-error-monitor.readthedocs.io/en/latest/
140+
--------------
141+
This has got extensive document browse at https://error-tracker.readthedocs.io/en/latest/
54142

55143
All docs are in `docs/source`
56144

@@ -62,27 +150,36 @@ Examples
62150
Several usage examples are included in the */tests* folder. Please feel free to add your own examples, or improve
63151
on some of the existing ones, and then submit them via GitHub as a *pull-request*.
64152

65-
You can see some of these examples in action at https://github.com/sonus21/flask-error-monitor/tree/master/examples.
153+
You can see some of these examples in action at https://github.com/sonus21/error-tracker/tree/master/examples
66154
To run the examples on your local environment, one at a time, do something like::
67155

68-
cd flask-error-monitor
69-
python examples/simple/app.py
156+
cd error-tracker/examples
157+
158+
159+
Django::
160+
161+
cd error-tracker/examples
162+
cd DjangoSample
163+
python manage.py runserver
164+
165+
Flask::
166+
167+
cd flask-sample
168+
python app.py
70169

71170

72171
Tests
73172
-----
74-
Test are run with *nose*. If you are not familiar with this package you can get some more info from `their website <https://nose.readthedocs.io/>`_.
75-
76173
To run the tests, from the project directory, simply::
77174

78175
pip install -r requirements-dev.txt
79-
nosetests
176+
bash tests/run-tests.sh
80177

81178
You should see output similar to::
82179

83180
.............................................
84181
----------------------------------------------------------------------
85-
Ran 26 tests in 1.144s
182+
Ran 29 tests in 1.144s
86183

87184
OK
88185

docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# You can set these variables from the command line.
55
SPHINXOPTS =
66
SPHINXBUILD = sphinx-build
7-
SPHINXPROJ = flask-error-monitor
7+
SPHINXPROJ = error-tracker
88
SOURCEDIR = source
99
BUILDDIR = build
1010

docs/make.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if "%SPHINXBUILD%" == "" (
99
)
1010
set SOURCEDIR=source
1111
set BUILDDIR=build
12-
set SPHINXPROJ=flask-error-monitor
12+
set SPHINXPROJ=error-tracker
1313

1414
if "%1" == "" goto help
1515

docs/source/conf.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
#
1515
import os
1616
import sys
17-
sys.path.insert(0, os.path.abspath('../flask_error'))
17+
sys.path.insert(0, os.path.abspath('../error_tracker'))
1818

1919

2020
# -- Project information -----------------------------------------------------
2121

22-
project = u'flask-error-monitor'
23-
copyright = u'2018, Sonu Kumar'
22+
project = u'error-tracker'
23+
copyright = u'2019, Sonu Kumar'
2424
author = u'Sonu Kumar'
2525

2626
# The short X.Y version
@@ -107,7 +107,7 @@
107107
# -- Options for HTMLHelp output ---------------------------------------------
108108

109109
# Output file base name for HTML help builder.
110-
htmlhelp_basename = 'flask-error-monitordoc'
110+
htmlhelp_basename = 'error-tracker-doc'
111111

112112

113113
# -- Options for LaTeX output ------------------------------------------------
@@ -134,7 +134,7 @@
134134
# (source start file, target name, title,
135135
# author, documentclass [howto, manual, or own class]).
136136
latex_documents = [
137-
(master_doc, 'flask-error-monitor.tex', u'flask-error-monitor Documentation',
137+
(master_doc, 'error-tracker.tex', u'error-tracker Documentation',
138138
u'Sonu Kumar', 'manual'),
139139
]
140140

@@ -144,7 +144,7 @@
144144
# One entry per manual page. List of tuples
145145
# (source start file, name, description, authors, manual section).
146146
man_pages = [
147-
(master_doc, 'flask-error-monitor', u'flask-error-monitor Documentation',
147+
(master_doc, 'error-tracker', u'error-tracker Documentation',
148148
[author], 1)
149149
]
150150

@@ -155,8 +155,8 @@
155155
# (source start file, target name, title, author,
156156
# dir menu entry, description, category)
157157
texinfo_documents = [
158-
(master_doc, 'flask-error-monitor', u'flask-error-monitor Documentation',
159-
author, 'flask-error-monitor', 'One line description of project.',
158+
(master_doc, 'error-tracker', u'error-tracker Documentation',
159+
author, 'error-tracker', 'Error Tracker Modules for Flask, Django and Python',
160160
'Miscellaneous'),
161161
]
162162

0 commit comments

Comments
 (0)