django-q2-sentry 0.1.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- django_q2_sentry/__init__.py +6 -0
- django_q2_sentry/py.typed +0 -0
- django_q2_sentry/sentry.py +59 -0
- django_q2_sentry-0.1.7.dist-info/METADATA +44 -0
- django_q2_sentry-0.1.7.dist-info/RECORD +7 -0
- django_q2_sentry-0.1.7.dist-info/WHEEL +4 -0
- django_q2_sentry-0.1.7.dist-info/licenses/LICENSE.txt +17 -0
|
File without changes
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import traceback
|
|
3
|
+
from types import FrameType, TracebackType
|
|
4
|
+
|
|
5
|
+
import sentry_sdk
|
|
6
|
+
from sentry_sdk.integrations.logging import ignore_logger
|
|
7
|
+
|
|
8
|
+
# Important to not log the logger.error messages from django-q
|
|
9
|
+
# We only want to catch the exceptions, not the logger
|
|
10
|
+
ignore_logger("django-q")
|
|
11
|
+
ignore_logger("django_q")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def return_task_from_stack(tb: TracebackType | None) -> dict:
|
|
15
|
+
"""
|
|
16
|
+
Function returns task information from stack trace if available
|
|
17
|
+
Used to tag
|
|
18
|
+
:param tb: traceback
|
|
19
|
+
:return return_task: dict
|
|
20
|
+
"""
|
|
21
|
+
if not tb:
|
|
22
|
+
tb = sys.exc_info()[2]
|
|
23
|
+
while 1:
|
|
24
|
+
if not tb or not tb.tb_next:
|
|
25
|
+
break
|
|
26
|
+
tb = tb.tb_next
|
|
27
|
+
stack: list[FrameType] = []
|
|
28
|
+
f: FrameType | None = tb.tb_frame if tb else None
|
|
29
|
+
while f:
|
|
30
|
+
stack.append(f)
|
|
31
|
+
f = f.f_back
|
|
32
|
+
stack.reverse()
|
|
33
|
+
traceback.print_exc()
|
|
34
|
+
for frame in stack:
|
|
35
|
+
for key, value in frame.f_locals.items():
|
|
36
|
+
if (
|
|
37
|
+
"task" == key
|
|
38
|
+
and isinstance(value, dict)
|
|
39
|
+
and value.get("id", False)
|
|
40
|
+
and value.get("func")
|
|
41
|
+
):
|
|
42
|
+
return value
|
|
43
|
+
return {}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class Sentry:
|
|
47
|
+
def __init__(self, dsn, **kwargs):
|
|
48
|
+
if not sentry_sdk.is_initialized():
|
|
49
|
+
sentry_sdk.init(dsn, **kwargs)
|
|
50
|
+
|
|
51
|
+
def report(self):
|
|
52
|
+
error = sys.exc_info()
|
|
53
|
+
tb = error[2]
|
|
54
|
+
task = return_task_from_stack(tb)
|
|
55
|
+
with sentry_sdk.push_scope() as scope:
|
|
56
|
+
scope.set_extra("django_q_task_id", task.get("id", ""))
|
|
57
|
+
scope.set_extra("django_q_task_name", task.get("name", ""))
|
|
58
|
+
scope.set_extra("django_q_task_func", task.get("func", ""))
|
|
59
|
+
sentry_sdk.capture_exception(error=error)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: django-q2-sentry
|
|
3
|
+
Version: 0.1.7
|
|
4
|
+
Summary: Bringing Sentry error tracking to Django Q2
|
|
5
|
+
Author-email: Christo Goosen <christogoosen@gmail.com>, Daniel Welch <dwelch2102@gmail.com>, Rauli Laine <rauli.laine@treet.fi>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE.txt
|
|
8
|
+
Keywords: django-q,sentry
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Requires-Python: <4,>=3.10
|
|
13
|
+
Requires-Dist: sentry-sdk>=2.0.0
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# django-q2-sentry
|
|
18
|
+
|
|
19
|
+
A [Django Q2](https://github.com/django-q2/django-q2) Error Reporter plugin adding Sentry support.
|
|
20
|
+
# Before version 0.1.3 sentry raven was a dependency. After 0.1.3 sentry-sdk used as raven is being deprecated.
|
|
21
|
+
|
|
22
|
+
# Upgraded to sentry version 2.0.0 and higher.
|
|
23
|
+
# Added check to see if sentry already instantiated.
|
|
24
|
+
|
|
25
|
+
### Installation
|
|
26
|
+
|
|
27
|
+
This plugin is intended to be included with Django Q as [setuptools extra](https://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies).
|
|
28
|
+
|
|
29
|
+
`$ pip install django-q2[sentry]`
|
|
30
|
+
|
|
31
|
+
Or add `django-q2[sentry]` to `requirements.txt`.
|
|
32
|
+
|
|
33
|
+
> This plugin requires Django Q2 version 1.8.0 or greater.
|
|
34
|
+
|
|
35
|
+
### Usage
|
|
36
|
+
|
|
37
|
+
Configure Sentry via the Django Q `Q_CLUSTER` dictionary in your Django project's `settings.py`. It is important that the `sentry` key be set in the `error_reporter` dictionary, as this name aligns with the project's entry point for this plugin. The only required configuration entry is your Sentry DSN.
|
|
38
|
+
If sentry is init has been called in your code already, we will use Django's existing Sentry configuration.
|
|
39
|
+
```python
|
|
40
|
+
Q_CLUSTER = {
|
|
41
|
+
"error_reporter": {"sentry": {"dsn": "https://******@sentry.io/<project>"}}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
Please check the [python sentry client configuration docs](https://docs.sentry.io/platforms/python/) for more options. Additional key-value pairs defined in `Q_CLUSTER['error_reporter']['sentry']` are passed directly as kwargs to instantiation of [`sentry.sentry_sdk`](https://docs.sentry.io/platforms/python/configuration/options/).
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
django_q2_sentry/__init__.py,sha256=Y-iel191L-zApVdj704sw41qVC7hFvxfN6GV49f1lDI,70
|
|
2
|
+
django_q2_sentry/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
django_q2_sentry/sentry.py,sha256=vO3sXnW-kQBgBltgybzrOLgCoNJ105GltJjC36CS_3c,1743
|
|
4
|
+
django_q2_sentry-0.1.7.dist-info/METADATA,sha256=X9WNOUfTlgErtN3c5amkLd6Vr0Ce8lo9WC30flUeGPA,2131
|
|
5
|
+
django_q2_sentry-0.1.7.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
6
|
+
django_q2_sentry-0.1.7.dist-info/licenses/LICENSE.txt,sha256=ukEi8E0PKq1dQGTXHUflg3rppLymwAhr7il9x-0nPgg,1062
|
|
7
|
+
django_q2_sentry-0.1.7.dist-info/RECORD,,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
Copyright (c) 2018 YOUR NAME
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
The above copyright notice and this permission notice shall be included in all
|
|
10
|
+
copies or substantial portions of the Software.
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
12
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
13
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
14
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
15
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
16
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
17
|
+
SOFTWARE.
|