feat(observe): main.py 挂中间件 + lifespan 启停上报 worker

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
guke
2026-07-06 12:14:14 +08:00
parent a5f63cb53c
commit 0cf4cc706b
2 changed files with 17 additions and 0 deletions
+7
View File
@@ -225,3 +225,10 @@ async def test_stop_flushes_remaining_and_closes_client(monkeypatch):
assert b'"n"' in posted["body"] # 关停时把剩余事件发了出去
assert observe_worker._client is None # client 已关闭并置空
def test_app_has_metrics_middleware():
from app.main import app
names = [m.cls.__name__ for m in app.user_middleware]
assert "RequestMetricsMiddleware" in names