aissue 1.0.0__tar.gz → 2.0.0__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.
Files changed (37) hide show
  1. aissue-2.0.0/LICENSE +21 -0
  2. aissue-2.0.0/PKG-INFO +261 -0
  3. aissue-2.0.0/README.md +192 -0
  4. aissue-2.0.0/aissue/__init__.py +17 -0
  5. aissue-2.0.0/aissue/asgi.py +135 -0
  6. aissue-2.0.0/aissue/breadcrumbs.py +173 -0
  7. aissue-2.0.0/aissue/client.py +415 -0
  8. aissue-2.0.0/aissue/fastapi.py +30 -0
  9. aissue-2.0.0/aissue/flask.py +150 -0
  10. aissue-2.0.0/aissue/integrations.py +173 -0
  11. aissue-2.0.0/aissue/logging.py +31 -0
  12. aissue-2.0.0/aissue/middleware.py +207 -0
  13. aissue-2.0.0/aissue/scrubbing.py +148 -0
  14. aissue-2.0.0/aissue.egg-info/PKG-INFO +261 -0
  15. {aissue-1.0.0 → aissue-2.0.0}/aissue.egg-info/SOURCES.txt +14 -2
  16. aissue-2.0.0/aissue.egg-info/requires.txt +22 -0
  17. {aissue-1.0.0 → aissue-2.0.0}/aissue.egg-info/top_level.txt +0 -1
  18. aissue-2.0.0/setup.py +81 -0
  19. aissue-2.0.0/tests/test_asgi.py +230 -0
  20. aissue-2.0.0/tests/test_breadcrumbs.py +330 -0
  21. aissue-2.0.0/tests/test_client_extras.py +236 -0
  22. aissue-2.0.0/tests/test_flask.py +144 -0
  23. {aissue-1.0.0 → aissue-2.0.0}/tests/test_middleware.py +82 -20
  24. aissue-2.0.0/tests/test_sdk.py +182 -0
  25. aissue-1.0.0/PKG-INFO +0 -180
  26. aissue-1.0.0/README.md +0 -133
  27. aissue-1.0.0/aissue/__init__.py +0 -5
  28. aissue-1.0.0/aissue/middleware.py +0 -143
  29. aissue-1.0.0/aissue.egg-info/PKG-INFO +0 -180
  30. aissue-1.0.0/aissue.egg-info/requires.txt +0 -8
  31. aissue-1.0.0/setup.py +0 -55
  32. aissue-1.0.0/tests/__init__.py +0 -1
  33. aissue-1.0.0/tests/urls.py +0 -15
  34. {aissue-1.0.0 → aissue-2.0.0}/aissue/apps.py +0 -0
  35. {aissue-1.0.0 → aissue-2.0.0}/aissue/exceptions.py +0 -0
  36. {aissue-1.0.0 → aissue-2.0.0}/aissue.egg-info/dependency_links.txt +0 -0
  37. {aissue-1.0.0 → aissue-2.0.0}/setup.cfg +0 -0
aissue-2.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 AIssue Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
aissue-2.0.0/PKG-INFO ADDED
@@ -0,0 +1,261 @@
1
+ Metadata-Version: 2.4
2
+ Name: aissue
3
+ Version: 2.0.0
4
+ Summary: Report errors from Python, Django, Flask and FastAPI apps to AIssue
5
+ Home-page: https://aissue.dev
6
+ Author: AIssue Team
7
+ Author-email: support@aissue.dev
8
+ License: MIT
9
+ Project-URL: Homepage, https://aissue.dev
10
+ Project-URL: Setup guide, https://aissue.dev/setup/
11
+ Project-URL: Documentation, https://aissue.dev/install/python.md
12
+ Keywords: django flask fastapi starlette asgi error monitoring error tracking breadcrumbs sentry-compatible aissue
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Programming Language :: Python :: 3.14
25
+ Classifier: Framework :: Django
26
+ Classifier: Framework :: Django :: 4.2
27
+ Classifier: Framework :: Django :: 5.0
28
+ Classifier: Framework :: Django :: 5.1
29
+ Classifier: Framework :: Django :: 5.2
30
+ Classifier: Framework :: Django :: 6.0
31
+ Classifier: Framework :: Flask
32
+ Classifier: Framework :: FastAPI
33
+ Classifier: Topic :: Software Development :: Bug Tracking
34
+ Classifier: Topic :: System :: Monitoring
35
+ Requires-Python: >=3.8
36
+ Description-Content-Type: text/markdown
37
+ License-File: LICENSE
38
+ Requires-Dist: requests>=2.25.0
39
+ Provides-Extra: django
40
+ Requires-Dist: Django>=3.2; extra == "django"
41
+ Provides-Extra: flask
42
+ Requires-Dist: Flask>=2.2; extra == "flask"
43
+ Provides-Extra: fastapi
44
+ Requires-Dist: fastapi>=0.95; extra == "fastapi"
45
+ Provides-Extra: starlette
46
+ Requires-Dist: starlette>=0.27; extra == "starlette"
47
+ Provides-Extra: dev
48
+ Requires-Dist: pytest>=6.0; extra == "dev"
49
+ Requires-Dist: pytest-django>=4.0; extra == "dev"
50
+ Requires-Dist: Flask>=2.2; extra == "dev"
51
+ Requires-Dist: fastapi>=0.95; extra == "dev"
52
+ Requires-Dist: httpx>=0.23; extra == "dev"
53
+ Requires-Dist: black>=21.0; extra == "dev"
54
+ Requires-Dist: flake8>=3.8; extra == "dev"
55
+ Dynamic: author
56
+ Dynamic: author-email
57
+ Dynamic: classifier
58
+ Dynamic: description
59
+ Dynamic: description-content-type
60
+ Dynamic: home-page
61
+ Dynamic: keywords
62
+ Dynamic: license
63
+ Dynamic: license-file
64
+ Dynamic: project-url
65
+ Dynamic: provides-extra
66
+ Dynamic: requires-dist
67
+ Dynamic: requires-python
68
+ Dynamic: summary
69
+
70
+ # aissue: error reporting for Python, Django, Flask and FastAPI
71
+
72
+ Send your app's errors to [AIssue](https://aissue.dev), which groups them into issues, finds the code responsible and explains how to fix it.
73
+
74
+ ## Django: 3 steps
75
+
76
+ ```bash
77
+ pip install aissue
78
+ ```
79
+
80
+ ```python
81
+ # settings.py
82
+ MIDDLEWARE = [
83
+ # ... your existing middleware
84
+ "aissue.middleware.AIssueMiddleware",
85
+ ]
86
+ ```
87
+
88
+ ```bash
89
+ # where the app runs (.env, Docker, your host's settings)
90
+ AISSUE_DSN=https://<key>@<your-aissue-host>/<domain id>
91
+ ```
92
+
93
+ Copy the exact `AISSUE_DSN` from your domain page in AIssue (**Set up error reporting → Django**). That's it: unhandled view errors are reported when `DEBUG = False`, in a background thread, without slowing down requests.
94
+
95
+ ### Also report errors you catch and log
96
+
97
+ ```python
98
+ LOGGING = {
99
+ "version": 1,
100
+ "handlers": {
101
+ "console": {"class": "logging.StreamHandler"},
102
+ "aissue": {"class": "aissue.logging.AIssueHandler", "level": "ERROR"},
103
+ },
104
+ "root": {"handlers": ["console", "aissue"], "level": "INFO"},
105
+ }
106
+ ```
107
+
108
+ Any `logger.exception(...)` (or `logger.error(..., exc_info=True)`) is then reported. Records without exception information are ignored.
109
+
110
+ ## Flask
111
+
112
+ ```bash
113
+ pip install "aissue[flask]"
114
+ ```
115
+
116
+ ```python
117
+ from flask import Flask
118
+ from aissue.flask import AIssue
119
+
120
+ app = Flask(__name__)
121
+ AIssue(app) # reads AISSUE_DSN from app.config or the environment
122
+ ```
123
+
124
+ Or with an application factory:
125
+
126
+ ```python
127
+ aissue_ext = AIssue()
128
+
129
+ def create_app():
130
+ app = Flask(__name__)
131
+ aissue_ext.init_app(app)
132
+ return app
133
+ ```
134
+
135
+ Unhandled exceptions (Flask's `got_request_exception`) are reported with status 500, the path, method, filtered query parameters, allow-listed headers, release, environment and the request's breadcrumbs. `abort(404)` and other HTTP errors are not reported. Nothing is reported while `app.debug` is on unless you pass `log_in_debug=True`.
136
+
137
+ Options, as keyword arguments or `AISSUE_*` keys in `app.config`: `dsn`, `environment`, `release`, `enabled`, `log_in_debug`, `header_allowlist`, `timeout`, `max_breadcrumbs`, `breadcrumb_log_level`, `http_breadcrumbs`. To send a user id, pass a callable that gets the request and returns an opaque id (never an email):
138
+
139
+ ```python
140
+ AIssue(app, user_id=lambda request: getattr(current_user, "id", None)) # e.g. Flask-Login
141
+ ```
142
+
143
+ ## FastAPI and Starlette
144
+
145
+ ```bash
146
+ pip install "aissue[fastapi]"
147
+ ```
148
+
149
+ ```python
150
+ from fastapi import FastAPI
151
+ import aissue.fastapi
152
+
153
+ app = FastAPI()
154
+ aissue.fastapi.init(app) # reads AISSUE_DSN; or init(app, dsn="https://...", environment="production")
155
+ ```
156
+
157
+ `aissue.fastapi.init` adds `aissue.asgi.AIssueMiddleware`, a plain ASGI middleware. Use it directly for Starlette or any other ASGI app:
158
+
159
+ ```python
160
+ from aissue.asgi import AIssueMiddleware
161
+
162
+ app.add_middleware(AIssueMiddleware, dsn="https://...") # Starlette / FastAPI
163
+ app = AIssueMiddleware(app) # any ASGI app
164
+ ```
165
+
166
+ Unhandled exceptions are reported and then re-raised, so the framework still answers 500. Handled errors (`HTTPException`, your exception handlers) are not reported. Events are handed to the SDK's background thread, so nothing blocks the event loop. Options: the same as Flask, plus `report_4xx`; `user_id` is a callable that gets the ASGI `scope` (by default the id of an authenticated Starlette `scope["user"]` is used).
167
+
168
+ ## Any other Python app (scripts, workers)
169
+
170
+ ```python
171
+ import aissue
172
+
173
+ aissue.init() # reads AISSUE_DSN; or aissue.init(dsn="https://...")
174
+
175
+ try:
176
+ charge(order)
177
+ except Exception as exc:
178
+ aissue.capture_exception(exc)
179
+ raise
180
+ ```
181
+
182
+ Without a DSN (or with an invalid one), `aissue.init()` logs a warning and returns a disabled client that does nothing: it never raises. Call `aissue.flush()` before a short-lived script exits to wait until queued events are sent.
183
+
184
+ ## Breadcrumbs
185
+
186
+ Each error is sent with a short trail of what happened before it (at most 100 items, oldest first):
187
+
188
+ - **Requests:** the incoming request (`GET /checkout`, path only).
189
+ - **Logs:** Python `logging` records at INFO and above (the level your loggers actually emit). The SDK's own logs and `urllib3`/`requests` internals are skipped.
190
+ - **Outbound HTTP:** calls made with `requests`: method, URL without the query string, and status code. Requests to AIssue itself are skipped.
191
+ - **Your own:**
192
+
193
+ ```python
194
+ import aissue
195
+
196
+ aissue.add_breadcrumb("Applied coupon", category="checkout", level="info", data={"items": 3})
197
+ aissue.clear_breadcrumbs()
198
+ ```
199
+
200
+ `type` can be `default`, `http`, `navigation`, `ui`, `log` or `query`; `level` one of `debug`, `info`, `warning`, `error`; `data` a flat dict of strings, numbers and booleans (at most 20 keys); messages are cut at 1000 characters.
201
+
202
+ Each request (Django, Flask, FastAPI/ASGI) gets its own trail, kept in a `contextvars` variable, so concurrent requests, threads and asyncio tasks never mix. Outside a request, breadcrumbs go to one process-wide trail. To give a background job its own trail:
203
+
204
+ ```python
205
+ with aissue.breadcrumb_scope():
206
+ process(job)
207
+ ```
208
+
209
+ Breadcrumb messages and data go through the same filters as the rest of the event: values under sensitive keys become `[Filtered]`, and secrets in text (`password=...`, `Bearer ...`, API keys, card numbers, email addresses) are redacted.
210
+
211
+ | Option (`aissue.init`, Flask, ASGI) | Django setting | Default | |
212
+ |---|---|---|---|
213
+ | `max_breadcrumbs` | `AISSUE_MAX_BREADCRUMBS` | `50` | Trail length, up to 100. `0` turns breadcrumbs off. |
214
+ | `breadcrumb_log_level` | `AISSUE_BREADCRUMB_LOG_LEVEL` | `"INFO"` | Lowest log level recorded. `None` turns log breadcrumbs off. |
215
+ | `http_breadcrumbs` | `AISSUE_HTTP_BREADCRUMBS` | `True` | Record outbound `requests` calls. |
216
+
217
+ If you already use the Sentry SDK, you don't need this package: set its DSN to the AIssue DSN instead (see your domain page).
218
+
219
+ ## Settings
220
+
221
+ All optional except the DSN. Each can also be an environment variable of the same name where noted.
222
+
223
+ | Setting | Default | |
224
+ |---|---|---|
225
+ | `AISSUE_DSN` | env `AISSUE_DSN` | `https://<key>@<host>/<domain id>` |
226
+ | `AISSUE_ENVIRONMENT` | env `AISSUE_ENVIRONMENT` | e.g. `production` |
227
+ | `AISSUE_RELEASE` | auto-detected | Deployed version. A git commit SHA lets AIssue read the exact deployed code. Detected from `AISSUE_RELEASE`, `VERCEL_GIT_COMMIT_SHA`, `RENDER_GIT_COMMIT`, `RAILWAY_GIT_COMMIT_SHA`, `HEROKU_SLUG_COMMIT`, `SOURCE_VERSION`, `CF_PAGES_COMMIT_SHA`, `GITHUB_SHA`, `COMMIT_SHA`, `GIT_SHA`, `GIT_COMMIT`. In Docker, pass one in, e.g. `--build-arg`/`ENV GIT_SHA=$(git rev-parse HEAD)`. |
228
+ | `AISSUE_ENABLED` | `True` (env `AISSUE_ENABLED` for `aissue.init`) | Turn reporting off. The Django middleware then removes itself. |
229
+ | `AISSUE_LOG_IN_DEBUG` | `False` | Also report while `DEBUG = True` |
230
+ | `AISSUE_REPORT_4XX` | `False` | Also report `Http404`, `PermissionDenied` and 400 errors |
231
+ | `AISSUE_SEND_REQUEST_BODY` | `False` | Send form data and JSON bodies (up to 64 KB), sensitive keys still filtered. Other bodies (plain text, XML, raw multipart) are never sent. |
232
+ | `AISSUE_SEND_USER_EMAIL` | `False` | Send the signed-in user's email (the user id is always sent) |
233
+ | `AISSUE_HEADER_ALLOWLIST` | safe default | Header names to send |
234
+ | `AISSUE_TIMEOUT` | `5` | Seconds per request to AIssue |
235
+ | `AISSUE_MAX_BREADCRUMBS`, `AISSUE_BREADCRUMB_LOG_LEVEL`, `AISSUE_HTTP_BREADCRUMBS` | | See [Breadcrumbs](#breadcrumbs) |
236
+
237
+ Legacy: `AISSUE_API_KEY` + `AISSUE_BASE_URL` still work instead of `AISSUE_DSN`.
238
+
239
+ A missing or invalid DSN never stops your app from starting: the middleware logs an `aissue` warning and removes itself.
240
+
241
+ ## What is sent
242
+
243
+ - **Error details:** exception type and message, the traceback, and structured stack frames (file, function, line, and whether it is your code or a library).
244
+ - **Request:** path, method, and query parameters. Values under sensitive-looking keys (`password`, `token`, `api_key`, `session`, `cookie`, `auth`, `card`…) are replaced with `[Filtered]`.
245
+ - **Headers:** an allowlist only (`User-Agent`, `Content-Type`, `Accept`, `Accept-Language`, `Host`, `Origin`, `Referer` without its query string…). Never `Cookie`, `Authorization`, API-key or client-IP headers.
246
+ - **User:** the signed-in user's id only.
247
+ - **Deployment:** release and environment.
248
+ - **Breadcrumbs:** see [Breadcrumbs](#breadcrumbs).
249
+
250
+ AIssue scrubs every event again on arrival. Sending never raises into your app. Events are dropped, not queued without limit, if AIssue is unreachable. The SDK backs off when AIssue asks it to (HTTP 429).
251
+
252
+ ## Troubleshooting
253
+
254
+ - **Nothing arrives:** check `DEBUG = False` (or `AISSUE_LOG_IN_DEBUG = True`; Flask: `app.debug` off or `log_in_debug=True`) and that `AISSUE_DSN` is set where the app runs. Look for `aissue` warnings in your logs, e.g. `AIssue is disabled` or a rejected key (401).
255
+ - **No log breadcrumbs:** only records your loggers actually emit are recorded. Python's default level is WARNING, so set `logging.basicConfig(level=logging.INFO)` (or your logging config) to see INFO records.
256
+ - **404s show up:** they're not reported unless `AISSUE_REPORT_4XX = True`.
257
+ - **Turn it off temporarily:** `AISSUE_ENABLED = False`.
258
+
259
+ ## License
260
+
261
+ MIT (see [LICENSE](LICENSE)).
aissue-2.0.0/README.md ADDED
@@ -0,0 +1,192 @@
1
+ # aissue: error reporting for Python, Django, Flask and FastAPI
2
+
3
+ Send your app's errors to [AIssue](https://aissue.dev), which groups them into issues, finds the code responsible and explains how to fix it.
4
+
5
+ ## Django: 3 steps
6
+
7
+ ```bash
8
+ pip install aissue
9
+ ```
10
+
11
+ ```python
12
+ # settings.py
13
+ MIDDLEWARE = [
14
+ # ... your existing middleware
15
+ "aissue.middleware.AIssueMiddleware",
16
+ ]
17
+ ```
18
+
19
+ ```bash
20
+ # where the app runs (.env, Docker, your host's settings)
21
+ AISSUE_DSN=https://<key>@<your-aissue-host>/<domain id>
22
+ ```
23
+
24
+ Copy the exact `AISSUE_DSN` from your domain page in AIssue (**Set up error reporting → Django**). That's it: unhandled view errors are reported when `DEBUG = False`, in a background thread, without slowing down requests.
25
+
26
+ ### Also report errors you catch and log
27
+
28
+ ```python
29
+ LOGGING = {
30
+ "version": 1,
31
+ "handlers": {
32
+ "console": {"class": "logging.StreamHandler"},
33
+ "aissue": {"class": "aissue.logging.AIssueHandler", "level": "ERROR"},
34
+ },
35
+ "root": {"handlers": ["console", "aissue"], "level": "INFO"},
36
+ }
37
+ ```
38
+
39
+ Any `logger.exception(...)` (or `logger.error(..., exc_info=True)`) is then reported. Records without exception information are ignored.
40
+
41
+ ## Flask
42
+
43
+ ```bash
44
+ pip install "aissue[flask]"
45
+ ```
46
+
47
+ ```python
48
+ from flask import Flask
49
+ from aissue.flask import AIssue
50
+
51
+ app = Flask(__name__)
52
+ AIssue(app) # reads AISSUE_DSN from app.config or the environment
53
+ ```
54
+
55
+ Or with an application factory:
56
+
57
+ ```python
58
+ aissue_ext = AIssue()
59
+
60
+ def create_app():
61
+ app = Flask(__name__)
62
+ aissue_ext.init_app(app)
63
+ return app
64
+ ```
65
+
66
+ Unhandled exceptions (Flask's `got_request_exception`) are reported with status 500, the path, method, filtered query parameters, allow-listed headers, release, environment and the request's breadcrumbs. `abort(404)` and other HTTP errors are not reported. Nothing is reported while `app.debug` is on unless you pass `log_in_debug=True`.
67
+
68
+ Options, as keyword arguments or `AISSUE_*` keys in `app.config`: `dsn`, `environment`, `release`, `enabled`, `log_in_debug`, `header_allowlist`, `timeout`, `max_breadcrumbs`, `breadcrumb_log_level`, `http_breadcrumbs`. To send a user id, pass a callable that gets the request and returns an opaque id (never an email):
69
+
70
+ ```python
71
+ AIssue(app, user_id=lambda request: getattr(current_user, "id", None)) # e.g. Flask-Login
72
+ ```
73
+
74
+ ## FastAPI and Starlette
75
+
76
+ ```bash
77
+ pip install "aissue[fastapi]"
78
+ ```
79
+
80
+ ```python
81
+ from fastapi import FastAPI
82
+ import aissue.fastapi
83
+
84
+ app = FastAPI()
85
+ aissue.fastapi.init(app) # reads AISSUE_DSN; or init(app, dsn="https://...", environment="production")
86
+ ```
87
+
88
+ `aissue.fastapi.init` adds `aissue.asgi.AIssueMiddleware`, a plain ASGI middleware. Use it directly for Starlette or any other ASGI app:
89
+
90
+ ```python
91
+ from aissue.asgi import AIssueMiddleware
92
+
93
+ app.add_middleware(AIssueMiddleware, dsn="https://...") # Starlette / FastAPI
94
+ app = AIssueMiddleware(app) # any ASGI app
95
+ ```
96
+
97
+ Unhandled exceptions are reported and then re-raised, so the framework still answers 500. Handled errors (`HTTPException`, your exception handlers) are not reported. Events are handed to the SDK's background thread, so nothing blocks the event loop. Options: the same as Flask, plus `report_4xx`; `user_id` is a callable that gets the ASGI `scope` (by default the id of an authenticated Starlette `scope["user"]` is used).
98
+
99
+ ## Any other Python app (scripts, workers)
100
+
101
+ ```python
102
+ import aissue
103
+
104
+ aissue.init() # reads AISSUE_DSN; or aissue.init(dsn="https://...")
105
+
106
+ try:
107
+ charge(order)
108
+ except Exception as exc:
109
+ aissue.capture_exception(exc)
110
+ raise
111
+ ```
112
+
113
+ Without a DSN (or with an invalid one), `aissue.init()` logs a warning and returns a disabled client that does nothing: it never raises. Call `aissue.flush()` before a short-lived script exits to wait until queued events are sent.
114
+
115
+ ## Breadcrumbs
116
+
117
+ Each error is sent with a short trail of what happened before it (at most 100 items, oldest first):
118
+
119
+ - **Requests:** the incoming request (`GET /checkout`, path only).
120
+ - **Logs:** Python `logging` records at INFO and above (the level your loggers actually emit). The SDK's own logs and `urllib3`/`requests` internals are skipped.
121
+ - **Outbound HTTP:** calls made with `requests`: method, URL without the query string, and status code. Requests to AIssue itself are skipped.
122
+ - **Your own:**
123
+
124
+ ```python
125
+ import aissue
126
+
127
+ aissue.add_breadcrumb("Applied coupon", category="checkout", level="info", data={"items": 3})
128
+ aissue.clear_breadcrumbs()
129
+ ```
130
+
131
+ `type` can be `default`, `http`, `navigation`, `ui`, `log` or `query`; `level` one of `debug`, `info`, `warning`, `error`; `data` a flat dict of strings, numbers and booleans (at most 20 keys); messages are cut at 1000 characters.
132
+
133
+ Each request (Django, Flask, FastAPI/ASGI) gets its own trail, kept in a `contextvars` variable, so concurrent requests, threads and asyncio tasks never mix. Outside a request, breadcrumbs go to one process-wide trail. To give a background job its own trail:
134
+
135
+ ```python
136
+ with aissue.breadcrumb_scope():
137
+ process(job)
138
+ ```
139
+
140
+ Breadcrumb messages and data go through the same filters as the rest of the event: values under sensitive keys become `[Filtered]`, and secrets in text (`password=...`, `Bearer ...`, API keys, card numbers, email addresses) are redacted.
141
+
142
+ | Option (`aissue.init`, Flask, ASGI) | Django setting | Default | |
143
+ |---|---|---|---|
144
+ | `max_breadcrumbs` | `AISSUE_MAX_BREADCRUMBS` | `50` | Trail length, up to 100. `0` turns breadcrumbs off. |
145
+ | `breadcrumb_log_level` | `AISSUE_BREADCRUMB_LOG_LEVEL` | `"INFO"` | Lowest log level recorded. `None` turns log breadcrumbs off. |
146
+ | `http_breadcrumbs` | `AISSUE_HTTP_BREADCRUMBS` | `True` | Record outbound `requests` calls. |
147
+
148
+ If you already use the Sentry SDK, you don't need this package: set its DSN to the AIssue DSN instead (see your domain page).
149
+
150
+ ## Settings
151
+
152
+ All optional except the DSN. Each can also be an environment variable of the same name where noted.
153
+
154
+ | Setting | Default | |
155
+ |---|---|---|
156
+ | `AISSUE_DSN` | env `AISSUE_DSN` | `https://<key>@<host>/<domain id>` |
157
+ | `AISSUE_ENVIRONMENT` | env `AISSUE_ENVIRONMENT` | e.g. `production` |
158
+ | `AISSUE_RELEASE` | auto-detected | Deployed version. A git commit SHA lets AIssue read the exact deployed code. Detected from `AISSUE_RELEASE`, `VERCEL_GIT_COMMIT_SHA`, `RENDER_GIT_COMMIT`, `RAILWAY_GIT_COMMIT_SHA`, `HEROKU_SLUG_COMMIT`, `SOURCE_VERSION`, `CF_PAGES_COMMIT_SHA`, `GITHUB_SHA`, `COMMIT_SHA`, `GIT_SHA`, `GIT_COMMIT`. In Docker, pass one in, e.g. `--build-arg`/`ENV GIT_SHA=$(git rev-parse HEAD)`. |
159
+ | `AISSUE_ENABLED` | `True` (env `AISSUE_ENABLED` for `aissue.init`) | Turn reporting off. The Django middleware then removes itself. |
160
+ | `AISSUE_LOG_IN_DEBUG` | `False` | Also report while `DEBUG = True` |
161
+ | `AISSUE_REPORT_4XX` | `False` | Also report `Http404`, `PermissionDenied` and 400 errors |
162
+ | `AISSUE_SEND_REQUEST_BODY` | `False` | Send form data and JSON bodies (up to 64 KB), sensitive keys still filtered. Other bodies (plain text, XML, raw multipart) are never sent. |
163
+ | `AISSUE_SEND_USER_EMAIL` | `False` | Send the signed-in user's email (the user id is always sent) |
164
+ | `AISSUE_HEADER_ALLOWLIST` | safe default | Header names to send |
165
+ | `AISSUE_TIMEOUT` | `5` | Seconds per request to AIssue |
166
+ | `AISSUE_MAX_BREADCRUMBS`, `AISSUE_BREADCRUMB_LOG_LEVEL`, `AISSUE_HTTP_BREADCRUMBS` | | See [Breadcrumbs](#breadcrumbs) |
167
+
168
+ Legacy: `AISSUE_API_KEY` + `AISSUE_BASE_URL` still work instead of `AISSUE_DSN`.
169
+
170
+ A missing or invalid DSN never stops your app from starting: the middleware logs an `aissue` warning and removes itself.
171
+
172
+ ## What is sent
173
+
174
+ - **Error details:** exception type and message, the traceback, and structured stack frames (file, function, line, and whether it is your code or a library).
175
+ - **Request:** path, method, and query parameters. Values under sensitive-looking keys (`password`, `token`, `api_key`, `session`, `cookie`, `auth`, `card`…) are replaced with `[Filtered]`.
176
+ - **Headers:** an allowlist only (`User-Agent`, `Content-Type`, `Accept`, `Accept-Language`, `Host`, `Origin`, `Referer` without its query string…). Never `Cookie`, `Authorization`, API-key or client-IP headers.
177
+ - **User:** the signed-in user's id only.
178
+ - **Deployment:** release and environment.
179
+ - **Breadcrumbs:** see [Breadcrumbs](#breadcrumbs).
180
+
181
+ AIssue scrubs every event again on arrival. Sending never raises into your app. Events are dropped, not queued without limit, if AIssue is unreachable. The SDK backs off when AIssue asks it to (HTTP 429).
182
+
183
+ ## Troubleshooting
184
+
185
+ - **Nothing arrives:** check `DEBUG = False` (or `AISSUE_LOG_IN_DEBUG = True`; Flask: `app.debug` off or `log_in_debug=True`) and that `AISSUE_DSN` is set where the app runs. Look for `aissue` warnings in your logs, e.g. `AIssue is disabled` or a rejected key (401).
186
+ - **No log breadcrumbs:** only records your loggers actually emit are recorded. Python's default level is WARNING, so set `logging.basicConfig(level=logging.INFO)` (or your logging config) to see INFO records.
187
+ - **404s show up:** they're not reported unless `AISSUE_REPORT_4XX = True`.
188
+ - **Turn it off temporarily:** `AISSUE_ENABLED = False`.
189
+
190
+ ## License
191
+
192
+ MIT (see [LICENSE](LICENSE)).
@@ -0,0 +1,17 @@
1
+ __version__ = '2.0.0'
2
+ __author__ = 'AIssue Team'
3
+ __description__ = 'Report errors from Python, Django, Flask and FastAPI apps to AIssue'
4
+
5
+ _CLIENT_API = (
6
+ 'init', 'capture_exception', 'flush', 'get_client',
7
+ 'add_breadcrumb', 'clear_breadcrumbs', 'breadcrumb_scope',
8
+ )
9
+
10
+
11
+ def __getattr__(name):
12
+ # Lazy so that `import aissue` works before Django settings are configured
13
+ # and stays cheap for apps that only use one integration.
14
+ if name in _CLIENT_API:
15
+ from . import client
16
+ return getattr(client, name)
17
+ raise AttributeError(name)
@@ -0,0 +1,135 @@
1
+ """
2
+ ASGI integration: works with FastAPI, Starlette and any plain ASGI app.
3
+
4
+ pip install "aissue[fastapi]"
5
+
6
+ from aissue.asgi import AIssueMiddleware
7
+
8
+ app = FastAPI() # or Starlette(...)
9
+ app.add_middleware(AIssueMiddleware, dsn='https://<api key>@<aissue host>/<domain id>')
10
+
11
+ # plain ASGI
12
+ app = AIssueMiddleware(app) # reads AISSUE_DSN
13
+
14
+ Reports unhandled exceptions with the request path, method, query parameters
15
+ (filtered), allow-listed headers, release, environment and the breadcrumbs
16
+ recorded during the request, then re-raises them so the server or framework
17
+ still answers 500. Events are queued for the SDK's background thread: nothing
18
+ blocks the event loop.
19
+
20
+ Options: dsn, environment, release, enabled, header_allowlist, report_4xx,
21
+ user_id (callable(scope) -> opaque id), timeout, sync, before_send,
22
+ max_breadcrumbs, breadcrumb_log_level, http_breadcrumbs. Without a dsn/api_key
23
+ option the middleware uses the client from ``aissue.init()`` if there is one.
24
+ """
25
+ import logging
26
+ from urllib.parse import parse_qs
27
+
28
+ from . import breadcrumbs as _breadcrumbs
29
+ from . import client as _client_module
30
+ from .scrubbing import DEFAULT_HEADER_ALLOWLIST, filter_headers, scrub
31
+
32
+ logger = logging.getLogger('aissue')
33
+
34
+ _CLIENT_OPTIONS = ('dsn', 'api_key', 'base_url', 'environment', 'release', 'enabled', 'timeout', 'sync',
35
+ 'before_send', 'max_breadcrumbs', 'breadcrumb_log_level', 'http_breadcrumbs')
36
+
37
+
38
+ def _header_name(raw):
39
+ return '-'.join(part.capitalize() for part in raw.split('-'))
40
+
41
+
42
+ class AIssueMiddleware:
43
+ def __init__(self, app, *, header_allowlist=None, report_4xx=False, user_id=None, **options):
44
+ self.app = app
45
+ self.header_allowlist = (
46
+ frozenset(h.lower() for h in header_allowlist) if header_allowlist is not None
47
+ else DEFAULT_HEADER_ALLOWLIST
48
+ )
49
+ self.report_4xx = report_4xx
50
+ self.user_id = user_id
51
+ unknown = set(options) - set(_CLIENT_OPTIONS)
52
+ if unknown:
53
+ raise TypeError(f'Unknown AIssueMiddleware options: {", ".join(sorted(unknown))}')
54
+ existing = _client_module.get_client()
55
+ self._client = None
56
+ if options or existing is None:
57
+ try:
58
+ self._client = _client_module.init(options.pop('dsn', None), **options)
59
+ except Exception:
60
+ logger.warning('AIssue could not be configured; errors will not be reported', exc_info=True)
61
+
62
+ @property
63
+ def client(self):
64
+ return self._client if self._client is not None else _client_module.get_client()
65
+
66
+ async def __call__(self, scope, receive, send):
67
+ if scope.get('type') not in ('http', 'websocket'):
68
+ await self.app(scope, receive, send)
69
+ return
70
+ client = self.client
71
+ if client is None or not client.enabled:
72
+ await self.app(scope, receive, send)
73
+ return
74
+
75
+ token = _breadcrumbs.push_scope()
76
+ try:
77
+ try:
78
+ method = scope.get('method') or ('WEBSOCKET' if scope.get('type') == 'websocket' else '')
79
+ _client_module.add_incoming_request_breadcrumb(method, scope.get('path') or '/')
80
+ except Exception:
81
+ pass
82
+ try:
83
+ await self.app(scope, receive, send)
84
+ except Exception as exc:
85
+ self._capture(client, scope, exc)
86
+ raise
87
+ finally:
88
+ _breadcrumbs.pop_scope(token)
89
+
90
+ # --- capture -------------------------------------------------------------------
91
+ def _capture(self, client, scope, exc):
92
+ try:
93
+ status = getattr(exc, 'status_code', None)
94
+ status = status if isinstance(status, int) and 400 <= status < 600 else 500
95
+ if status < 500 and not self.report_4xx:
96
+ return
97
+ client.capture_exception(exc, **self._extract_request(scope, status))
98
+ except Exception:
99
+ logger.warning('Failed to report error to AIssue', exc_info=True)
100
+
101
+ def _extract_request(self, scope, status):
102
+ query = scope.get('query_string') or b''
103
+ try:
104
+ params = parse_qs(query.decode('latin-1'), keep_blank_values=True)
105
+ except Exception:
106
+ params = {}
107
+ pairs = []
108
+ for name, value in scope.get('headers') or ():
109
+ try:
110
+ pairs.append((_header_name(name.decode('latin-1')), value.decode('latin-1')))
111
+ except Exception:
112
+ continue
113
+ return {
114
+ 'error_code': status if scope.get('type') == 'http' else 0,
115
+ 'path': scope.get('path') or '',
116
+ 'method': scope.get('method') or ('WEBSOCKET' if scope.get('type') == 'websocket' else ''),
117
+ 'user_id': self._get_user_id(scope),
118
+ 'request_data': {'GET': scrub(params)},
119
+ 'headers': filter_headers(pairs, self.header_allowlist),
120
+ }
121
+
122
+ def _get_user_id(self, scope):
123
+ try:
124
+ if self.user_id is not None:
125
+ value = self.user_id(scope)
126
+ else:
127
+ # Starlette's AuthenticationMiddleware puts the user in the scope.
128
+ user = scope.get('user')
129
+ if user is None or not getattr(user, 'is_authenticated', False):
130
+ return None
131
+ value = getattr(user, 'identity', None) or getattr(user, 'id', None)
132
+ except Exception:
133
+ logger.warning('AIssue could not read the user id; sending none', exc_info=True)
134
+ return None
135
+ return None if value is None else str(value)