Skip to content

Error capture

With capture_errors=True (the default), the SDK hooks into:

  • sys.excepthook — uncaught exceptions on the main thread
  • threading.excepthook — uncaught exceptions in threads
  • The active asyncio event loop’s exception handler

No manual instrumentation required.

init(api_key="...", environment="prod", capture_errors=False)

In async apps, call init() inside the running event loop so the asyncio handler installs against the loop you’re actually using. A typical FastAPI startup hook:

from fastapi import FastAPI
from auralog import init
app = FastAPI()
@app.on_event("startup")
def _auralog_startup():
init(api_key="aura_your_api_key", environment="production")

Even with automatic capture, you can attach context at a catch site:

try:
process_order(order_id)
except OrderError as e:
auralog.error(
"order processing failed",
metadata={"order_id": order_id},
exc_info=e,
)
raise

This gives you the log entry with the traceback AND re-raises so existing error handling continues to work.

Django’s own error handling doesn’t go through sys.excepthook — requests are handled within the framework. To capture unhandled exceptions from request handlers, use the AuralogHandler on Django’s logger configuration or install middleware.

A simple configuration:

settings.py
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"auralog": {"class": "auralog.AuralogHandler", "level": "INFO"},
},
"root": {"handlers": ["auralog"], "level": "INFO"},
"loggers": {
"django.request": {"handlers": ["auralog"], "level": "ERROR", "propagate": False},
},
}

Background threads are handled automatically via threading.excepthook:

import threading
from auralog import init
init(api_key="aura_your_api_key", environment="production")
def worker():
raise RuntimeError("background worker died")
# This exception will surface in Auralog — no extra setup
threading.Thread(target=worker).start()