Christian Kniep commited on
Commit
196e0b9
·
1 Parent(s): 5d3ee93

ignore logging of jstreamlit path

Browse files
Files changed (1) hide show
  1. 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
- # Get user_id from session if available
274
- user_id = None
275
- try:
276
- from flask import session
277
-
278
- user_id = session.get("user_id")
279
- except Exception:
280
- pass
281
-
282
- # Log request with structured data
283
- extra = {
284
- "request_id": g.request_id,
285
- "duration_ms": round(duration_ms, 2),
286
- "status_code": response.status_code,
287
- "method": request.method,
288
- "path": request.path,
289
- }
290
- if user_id:
291
- extra["user_id"] = user_id
292
- if hasattr(g, "backend_latency_ms"):
293
- extra["backend_latency_ms"] = round(g.backend_latency_ms, 2)
294
-
295
- app.logger.info(
296
- f"{request.method} {request.path} {response.status_code}",
297
- extra=extra,
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"):