devalerts 0.2.0__tar.gz → 0.2.1__tar.gz
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.
- {devalerts-0.2.0 → devalerts-0.2.1}/PKG-INFO +5 -1
- {devalerts-0.2.0 → devalerts-0.2.1}/README.md +4 -0
- {devalerts-0.2.0 → devalerts-0.2.1}/pyproject.toml +1 -1
- {devalerts-0.2.0 → devalerts-0.2.1}/src/devalerts/_alert.py +23 -10
- {devalerts-0.2.0 → devalerts-0.2.1}/src/devalerts/_telegram.py +3 -1
- {devalerts-0.2.0 → devalerts-0.2.1}/LICENSE +0 -0
- {devalerts-0.2.0 → devalerts-0.2.1}/src/devalerts/__init__.py +0 -0
- {devalerts-0.2.0 → devalerts-0.2.1}/src/devalerts/_celery.py +0 -0
- {devalerts-0.2.0 → devalerts-0.2.1}/src/devalerts/_store.py +0 -0
- {devalerts-0.2.0 → devalerts-0.2.1}/src/devalerts/cli.py +0 -0
- {devalerts-0.2.0 → devalerts-0.2.1}/src/devalerts/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: devalerts
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Send unhandled Python exceptions straight to a Telegram chat. No backend, no account, no database — just your own bot token.
|
|
5
5
|
Keywords: telegram,error-tracking,exception-monitoring,alerts,logging,monitoring,asgi
|
|
6
6
|
Author: sslinNn
|
|
@@ -94,6 +94,10 @@ devalerts.init(bot_token="123456:ABC-DEF...", chat_id=123456789)
|
|
|
94
94
|
That's it — any unhandled exception (including ones raised in threads) now
|
|
95
95
|
also lands in your Telegram chat.
|
|
96
96
|
|
|
97
|
+
The traceback itself arrives folded into a collapsed quote — the exception
|
|
98
|
+
type, message, and host are visible right away, tap to expand the full
|
|
99
|
+
traceback. Keeps a big stack trace from taking over the chat.
|
|
100
|
+
|
|
97
101
|
## Grouping, rate limiting, and the dashboard
|
|
98
102
|
|
|
99
103
|
Exceptions are grouped by fingerprint (exception type + file + line where it
|
|
@@ -67,6 +67,10 @@ devalerts.init(bot_token="123456:ABC-DEF...", chat_id=123456789)
|
|
|
67
67
|
That's it — any unhandled exception (including ones raised in threads) now
|
|
68
68
|
also lands in your Telegram chat.
|
|
69
69
|
|
|
70
|
+
The traceback itself arrives folded into a collapsed quote — the exception
|
|
71
|
+
type, message, and host are visible right away, tap to expand the full
|
|
72
|
+
traceback. Keeps a big stack trace from taking over the chat.
|
|
73
|
+
|
|
70
74
|
## Grouping, rate limiting, and the dashboard
|
|
71
75
|
|
|
72
76
|
Exceptions are grouped by fingerprint (exception type + file + line where it
|
|
@@ -9,6 +9,10 @@ import traceback
|
|
|
9
9
|
_MAX_MESSAGE_LENGTH = 4096
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
def _escape_html(text: str) -> str:
|
|
13
|
+
return text.replace("&", "&").replace("<", "<").replace(">", ">")
|
|
14
|
+
|
|
15
|
+
|
|
12
16
|
def _format_context(tags: dict[str, str] | None) -> str:
|
|
13
17
|
try:
|
|
14
18
|
hostname = socket.gethostname()
|
|
@@ -27,16 +31,25 @@ def _format_alert(
|
|
|
27
31
|
if skipped:
|
|
28
32
|
header += f"\n⚠️ Повторилась ещё {skipped} раз(а) с последнего алерта"
|
|
29
33
|
body = "".join(traceback.format_exception(exc_type, exc_value, tb))
|
|
30
|
-
|
|
31
|
-
if len(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
|
|
35
|
+
if len(header) + 2 + len(body) > _MAX_MESSAGE_LENGTH:
|
|
36
|
+
marker = "\n\n...(truncated)...\n"
|
|
37
|
+
# ponytail: header itself can exceed the limit if exc_value's str() is huge
|
|
38
|
+
# (e.g. a validation error echoing a large payload) — keep can go negative,
|
|
39
|
+
# so clamp it; the header itself gets hard-truncated as a backstop. The "2"
|
|
40
|
+
# accounts for the "\n\n" separator joined in below.
|
|
41
|
+
keep = max(_MAX_MESSAGE_LENGTH - len(header) - 2 - len(marker), 0)
|
|
42
|
+
body = f"{marker}{body[-keep:]}" if keep else ""
|
|
43
|
+
header = header[:_MAX_MESSAGE_LENGTH]
|
|
44
|
+
|
|
45
|
+
# Budgeted above against the plain text -- Telegram's 4096-char limit
|
|
46
|
+
# applies to the parsed (tag-stripped) text, not the raw HTML we send.
|
|
47
|
+
escaped_header = _escape_html(header)
|
|
48
|
+
if not body:
|
|
49
|
+
return escaped_header
|
|
50
|
+
return (
|
|
51
|
+
f"{escaped_header}\n\n<blockquote expandable>{_escape_html(body)}</blockquote>"
|
|
52
|
+
)
|
|
40
53
|
|
|
41
54
|
|
|
42
55
|
# ponytail: fixed pattern list, not exhaustive — catches common
|
|
@@ -40,7 +40,9 @@ def _log_failed_delivery(text: str) -> None:
|
|
|
40
40
|
|
|
41
41
|
def _send_telegram_message(bot_token: str, chat_id: int | str, text: str) -> bool:
|
|
42
42
|
url = f"https://api.telegram.org/bot{bot_token}/sendMessage"
|
|
43
|
-
payload = json.dumps(
|
|
43
|
+
payload = json.dumps(
|
|
44
|
+
{"chat_id": chat_id, "text": text, "parse_mode": "HTML"}
|
|
45
|
+
).encode("utf-8")
|
|
44
46
|
last_error: Exception | None = None
|
|
45
47
|
|
|
46
48
|
for attempt in range(_MAX_ATTEMPTS):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|