Skip to main content

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
    trap_logs=False,                # see "Bare log errors" below
)

What it hooks into

  • sys.excepthook — unhandled exceptions
  • threading.excepthook — unhandled exceptions in background threads (these never reach sys.excepthook)
  • Python logging — logger.exception() and logger.error(..., exc_info=True)
  • Celery — task failures via celery.signals.task_failure (auto-detected)

Bare log errors (opt-in)

By default, only log records carrying an exception are reported. Pass trap_logs=True to also report logger.error() / logger.critical() calls with no exception — they arrive as type LoggedError / LoggedCritical with the log call site as the frame. Off by default deliberately: in a chatty codebase every error-level log line becomes an event, and error trackers that default this on are famous for the resulting floods. The server's 5-minute dedup window still applies either way.

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",
    ...
]

Browser / JavaScript errors

Disabled for now. The relay shipped in 0.4.6–0.4.8 accepted anonymous posts by design (the browser can't hold a secret), and since ghosttrap streams now carry agent-to-agent messages that agents act on, an unauthenticated text channel into the stream is an injection risk we're not willing to carry. The /ghosttrap/js/ route answers 410 and forwards nothing. It will return once ingest distinguishes write-only tokens and reserves message types.

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.

Metadata

Release files for ghosttrap-sdk 0.4.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ghosttrap-sdk 0.4.9
File Size Uploaded Provenance Actions
ghosttrap_sdk-0.4.9.tar.gz 6.7 kB Without provenance Details for ghosttrap_sdk-0.4.9.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ghosttrap-sdk 0.4.9
File Interpreter ABI Platform Actions
ghosttrap_sdk-0.4.9-py3-none-any.whl Python 3 none any Details for ghosttrap_sdk-0.4.9-py3-none-any.whl

Total release size: 14.5 kB

Release files / ghosttrap_sdk-0.4.9.tar.gz

Download URL ghosttrap_sdk-0.4.9.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
808d5b0b132dc9682068a9f89dd86a82691cddbfc311682faa52391888a2b345
BLAKE2b-256 checksum
How to use checksums
07cfb1b854a39d2508de7f1e9648c4b634994dac6714c57836d8c6babe796ca5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.14

Release files / ghosttrap_sdk-0.4.9-py3-none-any.whl

Download URL ghosttrap_sdk-0.4.9-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dd6bd391a066c5770b0190a4fd086db1160f09d33094104e9087b985cb40586d
BLAKE2b-256 checksum
How to use checksums
3088f0ce7634ccd6144a2e997902d29ec9c39592f056eeb44c8a699a95652572
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.14

Security for ghosttrap-sdk 0.4.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page