Spaces:
Running
Running
Christian Kniep
commited on
Commit
·
196e0b9
1
Parent(s):
5d3ee93
ignore logging of jstreamlit path
Browse files- src/app.py +31 -26
src/app.py
CHANGED
|
@@ -270,32 +270,37 @@ def register_middleware(app):
|
|
| 270 |
if hasattr(g, "start_time"):
|
| 271 |
duration_ms = (time.time() - g.start_time) * 1000
|
| 272 |
|
| 273 |
-
#
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
user_id
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
|
| 300 |
# Finish tracing span
|
| 301 |
if hasattr(g, "span"):
|
|
|
|
| 270 |
if hasattr(g, "start_time"):
|
| 271 |
duration_ms = (time.time() - g.start_time) * 1000
|
| 272 |
|
| 273 |
+
# Skip logging for Streamlit internal requests unless in debug mode
|
| 274 |
+
is_streamlit_internal = request.path.startswith("/_stcore")
|
| 275 |
+
is_debug_mode = app.logger.level == logging.DEBUG
|
| 276 |
+
|
| 277 |
+
if not is_streamlit_internal or is_debug_mode:
|
| 278 |
+
# Get user_id from session if available
|
| 279 |
+
user_id = None
|
| 280 |
+
try:
|
| 281 |
+
from flask import session
|
| 282 |
+
|
| 283 |
+
user_id = session.get("user_id")
|
| 284 |
+
except Exception:
|
| 285 |
+
pass
|
| 286 |
+
|
| 287 |
+
# Log request with structured data
|
| 288 |
+
extra = {
|
| 289 |
+
"request_id": g.request_id,
|
| 290 |
+
"duration_ms": round(duration_ms, 2),
|
| 291 |
+
"status_code": response.status_code,
|
| 292 |
+
"method": request.method,
|
| 293 |
+
"path": request.path,
|
| 294 |
+
}
|
| 295 |
+
if user_id:
|
| 296 |
+
extra["user_id"] = user_id
|
| 297 |
+
if hasattr(g, "backend_latency_ms"):
|
| 298 |
+
extra["backend_latency_ms"] = round(g.backend_latency_ms, 2)
|
| 299 |
+
|
| 300 |
+
app.logger.info(
|
| 301 |
+
f"{request.method} {request.path} {response.status_code}",
|
| 302 |
+
extra=extra,
|
| 303 |
+
)
|
| 304 |
|
| 305 |
# Finish tracing span
|
| 306 |
if hasattr(g, "span"):
|