Wire Bugsnag into the API server#231
Wire Bugsnag into the API server#231morgan-wowk wants to merge 1 commit intobugsnag/instrumentation-modulefrom
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
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!
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

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.