Server SDK

Error monitoring for Python

One package for Django, Flask, and FastAPI. Middleware reports unhandled exceptions before your framework turns them into a response, with a manual capture API for everything else.

Frameworks Django · Flask · FastAPIRequires Python 3.8+Package errorgapSource ↗Package ↗Agent guide ↗
Install

Install

Install the extra for your framework so the right middleware ships with it.

sh
pip install "errorgap[django]"    # or [flask], [fastapi]
Configure

Configure

Call errorgap.init(...) once at startup, then register the middleware for your framework.

Django

At the bottom of settings.py:

python
import os
import errorgap

errorgap.init(
    endpoint=os.environ["ERRORGAP_ENDPOINT"],
    project_slug=os.environ["ERRORGAP_PROJECT_SLUG"],
    api_key=os.environ["ERRORGAP_API_KEY"],
)

Then add the middleware near the top of MIDDLEWARE:

python
MIDDLEWARE = [
    "errorgap.django.ErrorgapMiddleware",
    # ... existing middleware ...
]

Flask

python
import os
import errorgap
from errorgap.flask import init_app
from flask import Flask

errorgap.init(
    endpoint=os.environ["ERRORGAP_ENDPOINT"],
    project_slug=os.environ["ERRORGAP_PROJECT_SLUG"],
    api_key=os.environ["ERRORGAP_API_KEY"],
)

app = Flask(__name__)
init_app(app)  # connects Flask's got_request_exception signal

FastAPI

python
import os
import errorgap
from errorgap.fastapi import ErrorgapMiddleware
from fastapi import FastAPI

errorgap.init(
    endpoint=os.environ["ERRORGAP_ENDPOINT"],
    project_slug=os.environ["ERRORGAP_PROJECT_SLUG"],
    api_key=os.environ["ERRORGAP_API_KEY"],
)

app = FastAPI()
app.add_middleware(ErrorgapMiddleware)
Keep the key in an environment variable (or your framework's secret store) — never commit it to source control.
Trigger a test error

Trigger a test error

Add a throwaway route that raises, hit it once, then remove it. (From manage.py shell on Django you can raise Exception("Errorgap test error") directly.)

python
@app.route("/errorgap-test")   # Flask; FastAPI uses @app.get
def errorgap_test():
    raise Exception("Errorgap test error")
Verify

Verify the connection

Confirm your key and endpoint reach errorgap before wiring anything else — send one event straight to the ingestion API:

bash
curl -sS -X POST "$ERRORGAP_ENDPOINT/api/projects/$ERRORGAP_PROJECT_SLUG/notices" \
  -H "content-type: application/json" \
  -H "x-errorgap-project-key: $ERRORGAP_API_KEY" \
  -d '{"errors":[{"type":"ErrorgapInstallTest","message":"Errorgap install verification"}]}'

A 201 with a group_id means ingestion works (202 = received but sampled; 401 = wrong key). Then trigger the test error above through the SDK. Your onboarding screen's Verify step checks the stack off automatically once the first event lands — it polls every three seconds.

Next: the full ingestion API, or browse every SDK.