Startup/shutdown lifecycle change to lifespan in FastAPI 0.93+
0 reputation · 26 Dec 2022, 08:34 UTC
The goal is to configure application lifecycle handling so that monitoring alerts capture real startup and shutdown failures without generating noise from deprecation signals during a migration period.
FastAPI 0.93 introduced the lifespan async context manager as the documented standard for startup and shutdown management, with @app.on_event("startup") and @app.on_event("shutdown") emitting deprecation signals while still running. Mixing lifespan with on_event is supported for transition, but the interaction and execution order is not formally specified. No removal date for on_event has been published, leaving a decision point between suppressing warnings to reduce alert noise or tracking them as migration work.
What execution order is guaranteed when both a lifespan context manager and on_event startup/shutdown handlers are present in FastAPI 0.93+? Should deprecation warnings from on_event be classified as alertable events or as informational migration signals in log-based alerting? What criteria distinguish a lifespan startup failure from expected deprecation noise for alert routing?