Drop-in error reporter for ghosttrap.io
Project description
ghosttrap-sdk
Error reporting for Python apps, built for AI agents. Part of ghosttrap.
Install
pip install ghosttrap-sdk
Use
import ghosttrap
ghosttrap.init("t_your_token_here")
Get your token by running ghosttrap setup from ghosttrap-cli.
Optional kwargs
ghosttrap.init(
"t_your_token_here",
server="https://ghosttrap.io", # override only if self-hosting
send_user=False, # see "User context" below
)
What it hooks into
sys.excepthook— unhandled exceptions- Python logging —
logger.exception()andlogger.error(..., exc_info=True) - Celery — task failures via
celery.signals.task_failure(auto-detected)
What it sends
Every report includes the exception type, message, traceback, frames (file/line/function/code), and the server's hostname (socket.gethostname()).
Django
INSTALLED_APPS = [
...
"ghosttrap.django.GhostTrapApp",
]
MIDDLEWARE = [
"ghosttrap.django.GhostTrapMiddleware",
...
]
Manually trap an event
For errors you catch and handle but still want logged, or for non-exception conditions worth flagging:
import ghosttrap
try:
do_thing()
except ValueError as e:
ghosttrap.trap(e) # caught exception — sent with type, message, traceback
fallback()
ghosttrap.trap("payment gateway returned 503") # synthetic event labelled "TrappedEvent"
trap() accepts an exception instance or a string. Strings get the caller's stack attached and a TrappedEvent type so they're distinct from real exceptions in the CLI. Both go through the same 5-minute dedup window as the auto-hook.
User context
Off by default. Pass send_user=True to init() and the Django middleware will attach the authenticated user's id and username to each report. Has no effect outside Django.
ghosttrap.init("t_your_token_here", send_user=True)
Zero dependencies
Pure Python stdlib. No transitive dependencies in your production image.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ghosttrap_sdk-0.4.5.tar.gz.
File metadata
- Download URL: ghosttrap_sdk-0.4.5.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc9d7ae787664b95bcd32ed94e4739ee4eaf0705112c5ba6a0765fc97e20b9ab
|
|
| MD5 |
49cf9661f45a54fa60423f62e80eb369
|
|
| BLAKE2b-256 |
764a98336a54f1492e0deb2b5d9c5da0b5d3c9c24947a0c4478b2175b7aaf954
|
File details
Details for the file ghosttrap_sdk-0.4.5-py3-none-any.whl.
File metadata
- Download URL: ghosttrap_sdk-0.4.5-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2eedb6d9f95e81fd12eeb507ad7e77d3bae8f17899d4d9538f409a995ba66147
|
|
| MD5 |
bcbeea544c24c06261e8189d30724308
|
|
| BLAKE2b-256 |
4a33efb293a247289e637fd6b63749950788546a8c3c6e52c0da16a33c7fc5af
|