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.
Install the extra for your framework so the right middleware ships with it.
pip install "errorgap[django]" # or [flask], [fastapi]Call errorgap.init(...) once at startup, then register the middleware for your framework.
At the bottom of settings.py:
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:
MIDDLEWARE = [
"errorgap.django.ErrorgapMiddleware",
# ... existing middleware ...
]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 signalimport 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)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.)
@app.route("/errorgap-test") # Flask; FastAPI uses @app.get
def errorgap_test():
raise Exception("Errorgap test error")Confirm your key and endpoint reach errorgap before wiring anything else — send one event straight to the ingestion API:
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.