fastapi-radar 0.1.9__py3-none-any.whl → 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of fastapi-radar might be problematic. Click here for more details.
- fastapi_radar/__init__.py +1 -1
- fastapi_radar/capture.py +38 -10
- fastapi_radar/dashboard/dist/assets/{index-Dj9HCQum.js → index-31zorKsE.js} +62 -67
- fastapi_radar/dashboard/dist/index.html +1 -1
- fastapi_radar/middleware.py +15 -7
- {fastapi_radar-0.1.9.dist-info → fastapi_radar-0.2.0.dist-info}/METADATA +2 -1
- fastapi_radar-0.2.0.dist-info/RECORD +19 -0
- tests/test_async_radar.py +56 -0
- fastapi_radar-0.1.9.dist-info/RECORD +0 -18
- {fastapi_radar-0.1.9.dist-info → fastapi_radar-0.2.0.dist-info}/WHEEL +0 -0
- {fastapi_radar-0.1.9.dist-info → fastapi_radar-0.2.0.dist-info}/licenses/LICENSE +0 -0
- {fastapi_radar-0.1.9.dist-info → fastapi_radar-0.2.0.dist-info}/top_level.txt +0 -0
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>FastAPI Radar - Debugging Dashboard</title>
|
|
7
|
-
<script type="module" crossorigin src="/__radar/assets/index-
|
|
7
|
+
<script type="module" crossorigin src="/__radar/assets/index-31zorKsE.js"></script>
|
|
8
8
|
<link rel="stylesheet" crossorigin href="/__radar/assets/index-XlGcZj49.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
fastapi_radar/middleware.py
CHANGED
|
@@ -7,6 +7,7 @@ import uuid
|
|
|
7
7
|
from contextvars import ContextVar
|
|
8
8
|
from typing import Callable, Optional
|
|
9
9
|
|
|
10
|
+
from sqlalchemy.exc import SQLAlchemyError
|
|
10
11
|
from starlette.middleware.base import BaseHTTPMiddleware
|
|
11
12
|
from starlette.requests import Request
|
|
12
13
|
from starlette.responses import Response, StreamingResponse
|
|
@@ -118,16 +119,23 @@ class RadarMiddleware(BaseHTTPMiddleware):
|
|
|
118
119
|
|
|
119
120
|
async def capture_response():
|
|
120
121
|
response_body = ""
|
|
122
|
+
capturing = True
|
|
121
123
|
async for chunk in original_response.body_iterator:
|
|
122
124
|
yield chunk
|
|
123
|
-
if
|
|
125
|
+
if capturing:
|
|
124
126
|
response_body += chunk.decode("utf-8", errors="ignore")
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
response_body
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
127
|
+
try:
|
|
128
|
+
with self.get_session() as session:
|
|
129
|
+
captured_request.response_body = truncate_body(
|
|
130
|
+
response_body, self.max_body_size
|
|
131
|
+
)
|
|
132
|
+
session.add(captured_request)
|
|
133
|
+
session.commit()
|
|
134
|
+
except SQLAlchemyError:
|
|
135
|
+
# CapturedRequest record has been deleted.
|
|
136
|
+
capturing = False
|
|
137
|
+
else:
|
|
138
|
+
capturing = len(response_body) < self.max_body_size
|
|
131
139
|
|
|
132
140
|
response = StreamingResponse(
|
|
133
141
|
content=capture_response(),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fastapi-radar
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: A debugging dashboard for FastAPI applications with real-time monitoring
|
|
5
5
|
Home-page: https://github.com/doganarif/fastapi-radar
|
|
6
6
|
Author: Arif Dogan
|
|
@@ -29,6 +29,7 @@ Requires-Dist: pydantic
|
|
|
29
29
|
Requires-Dist: starlette
|
|
30
30
|
Requires-Dist: duckdb==1.1.3
|
|
31
31
|
Requires-Dist: duckdb-engine==0.17.0
|
|
32
|
+
Requires-Dist: aiosqlite>=0.21.0
|
|
32
33
|
Provides-Extra: dev
|
|
33
34
|
Requires-Dist: pytest; extra == "dev"
|
|
34
35
|
Requires-Dist: pytest-asyncio; extra == "dev"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
fastapi_radar/__init__.py,sha256=RC_pRDx1vkO5_-d_XA4VMJEdVBelwu3CxQrXCAEl8Uc,137
|
|
2
|
+
fastapi_radar/api.py,sha256=uuUQp-E8MBZf9bEklrRLfgXv2c0AYiE9yCI8FBIR8Fk,16136
|
|
3
|
+
fastapi_radar/capture.py,sha256=weWpI2HBb-qp04SZMWXt-Lx3NYo44WBvH65-Yyvv_UI,6623
|
|
4
|
+
fastapi_radar/middleware.py,sha256=qSELsASuZwpg4rsljQCU64fhkAYcOjadfiZICkZO7BA,8439
|
|
5
|
+
fastapi_radar/models.py,sha256=aOxShW8DeYKhehGL9tvBTSWkqqJSgDMKJKNQ1w_OKdE,5092
|
|
6
|
+
fastapi_radar/radar.py,sha256=sBmniNedkd_IWWBOqdgYBLmys2YE9MbGmz8kacDcGcg,15104
|
|
7
|
+
fastapi_radar/tracing.py,sha256=GNayJJaxZR68ZiT3Io9GUyd9SnbFrfXGnRRpQigLDL0,8798
|
|
8
|
+
fastapi_radar/utils.py,sha256=82cNXjbtm7oTaNRwrSy2fPWDVGi8XSk56C_8o7N7oRQ,1516
|
|
9
|
+
fastapi_radar/dashboard/dist/index.html,sha256=qLA_fwKrBIEDOYEuBU0ZlW8EbDy5rec-IaP6RIp67BA,436
|
|
10
|
+
fastapi_radar/dashboard/dist/assets/index-31zorKsE.js,sha256=Hul-8iFpscVAAFsmcQU5Ub2Smo6OCPnGZlCDGnEIItU,837403
|
|
11
|
+
fastapi_radar/dashboard/dist/assets/index-XlGcZj49.css,sha256=z2yLr4jYQoOM7KQ2aw5zrPpMlkr9dRvwBSGaxjzZNnc,35552
|
|
12
|
+
fastapi_radar-0.2.0.dist-info/licenses/LICENSE,sha256=0ga4BB6q-nqx6xlDRhtrgKrYs0HgX02PQyIzNFRK09Q,1067
|
|
13
|
+
tests/__init__.py,sha256=kAWaI50iJRZ4JlAdyt7FICgm8MsloZz0ZlsmhgLXBas,31
|
|
14
|
+
tests/test_async_radar.py,sha256=zsj2r6-q9WjjamLtzrIDWI8fxcBJ0oVOcynfvPlOhRE,1610
|
|
15
|
+
tests/test_radar.py,sha256=3F-_zdemPcgQnjP4kzCa7GhMxNJNYU0SgSWprctyXiA,2374
|
|
16
|
+
fastapi_radar-0.2.0.dist-info/METADATA,sha256=_Qmv_JSleXcpDOIk-6PoisOsK-nNmQiU5IW7ih5VAh0,7637
|
|
17
|
+
fastapi_radar-0.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
18
|
+
fastapi_radar-0.2.0.dist-info/top_level.txt,sha256=M-bALM-KDkiLcATq2aAx-BnG59Nv-GdFBzuzkUhiCa0,20
|
|
19
|
+
fastapi_radar-0.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from fastapi import FastAPI
|
|
2
|
+
from fastapi_radar import Radar
|
|
3
|
+
from sqlalchemy import Column, Integer, MetaData, String, Table, select
|
|
4
|
+
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
|
5
|
+
|
|
6
|
+
app = FastAPI()
|
|
7
|
+
engine = create_async_engine("sqlite+aiosqlite:///./app.db")
|
|
8
|
+
async_session: async_sessionmaker[AsyncSession] = async_sessionmaker(
|
|
9
|
+
engine, expire_on_commit=False
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
# 定义一个简单的测试表
|
|
13
|
+
metadata = MetaData()
|
|
14
|
+
users_table = Table(
|
|
15
|
+
"users",
|
|
16
|
+
metadata,
|
|
17
|
+
Column("id", Integer, primary_key=True, autoincrement=True),
|
|
18
|
+
Column("name", String(50), nullable=False),
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
radar = Radar(app, db_engine=engine)
|
|
23
|
+
radar.create_tables()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@app.on_event("startup")
|
|
27
|
+
async def on_startup() -> None:
|
|
28
|
+
"""应用启动时创建测试表并写入示例数据。"""
|
|
29
|
+
|
|
30
|
+
async with engine.begin() as conn:
|
|
31
|
+
await conn.run_sync(metadata.create_all)
|
|
32
|
+
|
|
33
|
+
async with async_session() as session:
|
|
34
|
+
result = await session.execute(select(users_table.c.id).limit(1))
|
|
35
|
+
if result.first() is None:
|
|
36
|
+
await session.execute(
|
|
37
|
+
users_table.insert(),
|
|
38
|
+
[{"name": "Alice"}, {"name": "Bob"}, {"name": "Carol"}],
|
|
39
|
+
)
|
|
40
|
+
await session.commit()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# Your routes work unchanged
|
|
44
|
+
@app.get("/users")
|
|
45
|
+
async def get_users():
|
|
46
|
+
async with async_session() as session:
|
|
47
|
+
result = await session.execute(select(users_table))
|
|
48
|
+
rows = result.mappings().all()
|
|
49
|
+
|
|
50
|
+
return {"users": [dict(row) for row in rows]}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
if __name__ == "__main__":
|
|
54
|
+
import uvicorn
|
|
55
|
+
|
|
56
|
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
fastapi_radar/__init__.py,sha256=Os2-UyRE7P9eMawgWenw_V4aa_08wp36xQ14G4fec_o,137
|
|
2
|
-
fastapi_radar/api.py,sha256=uuUQp-E8MBZf9bEklrRLfgXv2c0AYiE9yCI8FBIR8Fk,16136
|
|
3
|
-
fastapi_radar/capture.py,sha256=butzGPmjR8f3gdrNqh4iOlXD2WBD8Zh6CcSTDlnYR5o,5186
|
|
4
|
-
fastapi_radar/middleware.py,sha256=6FRlZa3XJwOA8UF5NkZ3pOXyK7F9P_ksvixf1CbFllk,8037
|
|
5
|
-
fastapi_radar/models.py,sha256=aOxShW8DeYKhehGL9tvBTSWkqqJSgDMKJKNQ1w_OKdE,5092
|
|
6
|
-
fastapi_radar/radar.py,sha256=sBmniNedkd_IWWBOqdgYBLmys2YE9MbGmz8kacDcGcg,15104
|
|
7
|
-
fastapi_radar/tracing.py,sha256=GNayJJaxZR68ZiT3Io9GUyd9SnbFrfXGnRRpQigLDL0,8798
|
|
8
|
-
fastapi_radar/utils.py,sha256=82cNXjbtm7oTaNRwrSy2fPWDVGi8XSk56C_8o7N7oRQ,1516
|
|
9
|
-
fastapi_radar/dashboard/dist/index.html,sha256=EaysaD1uPZhQplljsV-ytNhrXG-fgc1i9GHzn2i2PzM,436
|
|
10
|
-
fastapi_radar/dashboard/dist/assets/index-Dj9HCQum.js,sha256=HNTPaHPyqsprjI_hJpxnfJddpaBFtGylfdmnqSFw470,833887
|
|
11
|
-
fastapi_radar/dashboard/dist/assets/index-XlGcZj49.css,sha256=z2yLr4jYQoOM7KQ2aw5zrPpMlkr9dRvwBSGaxjzZNnc,35552
|
|
12
|
-
fastapi_radar-0.1.9.dist-info/licenses/LICENSE,sha256=0ga4BB6q-nqx6xlDRhtrgKrYs0HgX02PQyIzNFRK09Q,1067
|
|
13
|
-
tests/__init__.py,sha256=kAWaI50iJRZ4JlAdyt7FICgm8MsloZz0ZlsmhgLXBas,31
|
|
14
|
-
tests/test_radar.py,sha256=3F-_zdemPcgQnjP4kzCa7GhMxNJNYU0SgSWprctyXiA,2374
|
|
15
|
-
fastapi_radar-0.1.9.dist-info/METADATA,sha256=AZQMX_iDB8P989LFgDglUAeWhgAgDMls5LjRA93IvwU,7604
|
|
16
|
-
fastapi_radar-0.1.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
17
|
-
fastapi_radar-0.1.9.dist-info/top_level.txt,sha256=M-bALM-KDkiLcATq2aAx-BnG59Nv-GdFBzuzkUhiCa0,20
|
|
18
|
-
fastapi_radar-0.1.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|