Wire Bugsnag into the API server#231
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
| @app.exception_handler(Exception) | ||
| def handle_error(request: fastapi.Request, exc: BaseException): | ||
| exception_str = traceback.format_exception(type(exc), exc, exc.__traceback__) | ||
| bugsnag_instrumentation.notify(exc) |
There was a problem hiding this comment.
Sorry for the noise, I realize you mention this is not ready for review yet, but wanted to add this comment before I forget.
I really like how you added in the orchestrator stack for adding the execution.id to the exception for better tracebility. Not sure if there is anything like that now in the API level? I believe we are adding system level annotations to the source (UI, CLI/tangle-deploy), that "might" be nice to add to this to label the exception better.
Just a thought, if we don't have the plumbing now to easily do this, then not a concern.
There was a problem hiding this comment.
It is welcome. Good question / topic to look into!
There was a problem hiding this comment.
You're correct. We don't have any traces or contextual ids in the API level.
+1 that having the source would be great!
There was a problem hiding this comment.
I'll defer adding that to a future PR since the source has been in discussion recently and may change
f967108 to
bba37bb
Compare
cf06f0c to
248ce56
Compare
bba37bb to
d1e5bdb
Compare
66f4c0d to
c0d147f
Compare
d1e5bdb to
368e08e
Compare
c0d147f to
4a6f0bc
Compare
ff5439f to
765252d
Compare
4a6f0bc to
7a7696e
Compare
e7d28aa to
666bc18
Compare
7a7696e to
6842b69
Compare
666bc18 to
a5bc1e7
Compare
6842b69 to
936d216
Compare
a5bc1e7 to
cd51f98
Compare
936d216 to
514d0f0
Compare
cd51f98 to
d7ace7d
Compare
514d0f0 to
365eab5
Compare
365eab5 to
fb3d6ba
Compare
d7ace7d to
4c9bbf0
Compare
fb3d6ba to
2b50dde
Compare
4c9bbf0 to
5fc47fb
Compare
2b50dde to
83fb649
Compare
5fc47fb to
b73fa62
Compare
83fb649 to
3c2bd5a
Compare
b73fa62 to
f4d070d
Compare
3c2bd5a to
aff71b8
Compare
f4d070d to
df974a8
Compare
aff71b8 to
6b75f47
Compare
df974a8 to
5ef7052
Compare
6b75f47 to
dc99bb4
Compare
5ef7052 to
83977b0
Compare
Merge activity
|
83977b0 to
c18f430
Compare

TL;DR
Integrates Bugsnag error monitoring into the API server.
What changed?
tangle-api.BugsnagMiddlewareis conditionally added to the FastAPI middleware stack when Bugsnag is enabled.bugsnag_instrumentation.notify.How to test?
IS_BUGSNAG_ENABLEDisTrue, and that the app starts normally when Bugsnag is disabled.Why make this change?
To improve observability and error tracking in production by capturing and reporting unhandled exceptions to Bugsnag, enabling faster diagnosis and resolution of issues.
Bugsnag ASGI Middleware
BugsnagMiddleware(source) wraps the ASGI layer and automatically enriches every error event with request context:authorization,cookie,x-api-key, andproxy-authorizationredacted viaparams_filters"environment"tab — opt-in viasend_environment=True, off by defaultThe middleware and the explicit
bugsnag.notify()call inhandle_errorare complementary, not duplicative: FastAPI's exception handler consumes exceptions before they reach the ASGI layer, sohandle_errorcovers normal request errors whileBugsnagMiddlewareacts as a safety net for exceptions that escape FastAPI entirely (e.g. startup failures, middleware crashes).Additionally, every Bugsnag event — whether from the middleware or from a direct
notify()call — is enriched with a"tangle_context"tab via ourbefore_notifycallback, containing:request_id,user_id,pipeline_run_id, andexecution_idfrom the current request context.