Skip to main content

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 logginglogger.exception() and logger.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

ghosttrap_sdk-0.4.4.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ghosttrap_sdk-0.4.4-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file ghosttrap_sdk-0.4.4.tar.gz.

File metadata

  • Download URL: ghosttrap_sdk-0.4.4.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

Hashes for ghosttrap_sdk-0.4.4.tar.gz
Algorithm Hash digest
SHA256 79c6b1c19aee4b58b0ec5c84abeb09762ec51df3ed68b353eac5d439d54db383
MD5 f307a40c6a22886434b913bdf76794d6
BLAKE2b-256 44b062453d63fead9eb57f2bf370a49fda6d4d563cbf7cb5cd43a6847cfbbd77

See more details on using hashes here.

File details

Details for the file ghosttrap_sdk-0.4.4-py3-none-any.whl.

File metadata

  • Download URL: ghosttrap_sdk-0.4.4-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

Hashes for ghosttrap_sdk-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e7d9fa4916d60330013890e0c574ed40e94697acb2caf358cd2deb2e1961664f
MD5 7b26fc0d694f922d81aa5d09caf40a20
BLAKE2b-256 1e60bdf5f13f9be7ddcc5e9b5dfcb9c186872ec0622d69c2e4a3cb391cf3fe70

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page