errorgap
Python notifier for Errorgap. Captures exceptions, normalizes tracebacks with bounded source excerpts for readable frames, and ships notices to an Errorgap server. Single package covers plain Python, Django, Flask, and FastAPI.
Install
pip install errorgap
For framework integrations:
pip install "errorgap[django]" # or [flask], [fastapi]
Requires Python 3.9+.
Configure
import errorgap
errorgap.init(
endpoint=...,
project_slug=...,
api_key=...,
environment="production",
)
init reads the same values from ERRORGAP_ENDPOINT,
ERRORGAP_PROJECT_SLUG, ERRORGAP_PROJECT_ID, and ERRORGAP_API_KEY if you
don't pass them. By default it installs a sys.excepthook to catch
uncaught exceptions in scripts; pass capture_globals=False to skip.
Manual notification
try:
risky()
except Exception as exc:
errorgap.notify(exc, context={"component": "billing"})
raise
notify returns a DeliveryResult (status, body, error, queued).
The SDK never raises.
Django
Add to MIDDLEWARE:
MIDDLEWARE = [
"errorgap.django.ErrorgapMiddleware",
# ... your existing middleware ...
]
With apm_enabled=True each request is also an APM transaction grouped by
its URL pattern (/orders/<int:order_id>); errors raised during it carry its
transaction id, and the browser SDK's x-errorgap-trace header is recorded.
Record spans from a view with errorgap.django.spans(request).database(sql, ms).
Flask
from flask import Flask
from errorgap.flask import init_app
app = Flask(__name__)
init_app(app)
init_app also times each request as an APM transaction (sent with
apm_enabled=True) grouped by its URL rule (/orders/<int:id>), and errors
raised during the request carry its transaction id. Record spans from a view
with errorgap.flask.spans():
from errorgap.flask import spans
@app.route("/orders/<int:order_id>")
def order(order_id):
started = time.perf_counter()
row = db.execute("SELECT * FROM orders WHERE id = %s", (order_id,)).fetchone()
spans().database("SELECT * FROM orders WHERE id = %s", (time.perf_counter() - started) * 1000)
return row
WSGI
Any WSGI app gets the same request transactions from
errorgap.wsgi.ErrorgapMiddleware. Set environ["errorgap.route"] to the
matched route template to group requests (otherwise the raw path is used).
from errorgap.wsgi import ErrorgapMiddleware
application = ErrorgapMiddleware(application)
Transactions and jobs
with errorgap.track_transaction("GET", "/orders/{id}", "/orders/123") as txn:
txn.spans.database("SELECT * FROM orders WHERE id = 123", 4.2)
txn.status_code = 200
with errorgap.track_job("ReceiptJob", queue="mailers") as txn:
send_receipt()
Both time the block and deliver on exit even if it raises. Errors reported
inside carry the transaction id (context.transaction_id), so errorgap shows
the error a request raised on its trace. The id lives in a ContextVar, so
concurrent threads and asyncio tasks never share one;
errorgap.current_transaction_id() returns the id in effect.
Browser trace links
When the errorgap browser SDK (@errorgap/browser 0.3+) is on the page, its
API calls send an x-errorgap-trace header. The WSGI, Django and FastAPI
middleware (and so Flask's init_app) record it, and track_transaction(..., trace_id=header) accepts
it, so errorgap's browser Performance view links each call to the server
request that answered it. Malformed values are ignored.
FastAPI
from fastapi import FastAPI
from errorgap.fastapi import ErrorgapMiddleware
app = FastAPI()
app.add_middleware(ErrorgapMiddleware)
With apm_enabled=True each request is also an APM transaction grouped by
its route path (/orders/{order_id}); errors raised during it carry its
transaction id, and the browser SDK's x-errorgap-trace header is recorded.
Record spans from an endpoint with errorgap.fastapi.spans(request).database(sql, ms)
(take request: Request as a parameter).
Configuration reference
| Argument | Default | Notes |
|---|---|---|
endpoint |
ERRORGAP_ENDPOINT or http://127.0.0.1:3030 |
Base URL, no trailing slash |
project_slug |
ERRORGAP_PROJECT_SLUG |
Required |
project_id |
ERRORGAP_PROJECT_ID |
Optional, embedded in payload |
api_key |
ERRORGAP_API_KEY |
Sent as x-errorgap-project-key |
environment |
ERRORGAP_ENVIRONMENT, ENV, or development |
|
root_directory |
os.getcwd() |
Marks application frames; readable dependency frames also include bounded source excerpts |
async_ |
True |
Background-thread delivery |
logger |
logging.getLogger("errorgap") |
Pass None to silence |
filter_keys |
("password", "token", ...) |
Substring match, case-insensitive |
apm_enabled |
False |
Send APM transactions |
apm_sample_rate |
1.0 |
Fraction of transactions sent (errors are unaffected) |
capture_globals |
True |
Install sys.excepthook |
Graceful shutdown
errorgap.flush(timeout=5) # wait for queued deliveries
errorgap.shutdown(timeout=5) # flush + tear down background thread
Verify
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"}],"context":{"environment":"development"}}'
Then trigger a real error and confirm it appears in the Errorgap UI.
Development
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pytest
License
MIT.
Metadata
Release files for errorgap 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| errorgap-0.3.0.tar.gz | 20.6 kB | With provenance | Details for errorgap-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| errorgap-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for errorgap-0.3.0-py3-none-any.whl |
Total release size: 41.7 kB
Release files / errorgap-0.3.0.tar.gz
| Download URL | errorgap-0.3.0.tar.gz |
|---|---|
| Size | 20.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d42eb839190a9231ff81eeb8ddf6af39685ac0f1cc708da1afdaebe09b531de6
|
|
BLAKE2b-256 checksum How to use checksums |
e6b0cd04d833b68c6fcdb4dd2543b48b4db1365dd894a1731652696ce5a5dfe5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 4, 2026.
Transparency logRelease files / errorgap-0.3.0-py3-none-any.whl
| Download URL | errorgap-0.3.0-py3-none-any.whl |
|---|---|
| Size | 21.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8f15627d42fade02f7adbc2d3dfd8ff65f3ff114031d04aa4b3f14a539204d36
|
|
BLAKE2b-256 checksum How to use checksums |
820f8654acefe11cb3a0ab36f2c58acec6790cf2b21e43b189685ed0b77024a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 4, 2026.
Transparency logSecurity for errorgap 0.3.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for errorgap-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 4, 2026.
Transparency logA 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.