Skip to content

Commit d4d5a51

Browse files
committed
fix bug
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
1 parent 220e98c commit d4d5a51

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

mcpgateway/services/structured_logger.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,15 @@ def enrich(entry: Dict[str, Any]) -> Dict[str, Any]:
8181
entry["timestamp"] = datetime.now(timezone.utc)
8282

8383
# Add performance metrics if available
84-
perf_tracker = get_performance_tracker()
85-
if correlation_id and perf_tracker:
86-
current_ops = perf_tracker.get_current_operations(correlation_id)
87-
if current_ops:
88-
entry["active_operations"] = len(current_ops)
84+
try:
85+
perf_tracker = get_performance_tracker()
86+
if correlation_id and perf_tracker and hasattr(perf_tracker, 'get_current_operations'):
87+
current_ops = perf_tracker.get_current_operations(correlation_id)
88+
if current_ops:
89+
entry["active_operations"] = len(current_ops)
90+
except Exception:
91+
# Silently skip if performance tracker is unavailable or method doesn't exist
92+
pass
8993

9094
# Add OpenTelemetry trace context if available
9195
try:
@@ -257,7 +261,11 @@ def _persist_to_database(self, entry: Dict[str, Any], db: Optional[Session] = No
257261
db.commit()
258262

259263
except Exception as e:
260-
logger.error(f"Failed to persist log entry to database: {e}")
264+
logger.error(f"Failed to persist log entry to database: {e}", exc_info=True)
265+
# Also print to console for immediate visibility
266+
import traceback
267+
print(f"ERROR persisting log to database: {e}")
268+
traceback.print_exc()
261269
if db:
262270
db.rollback()
263271

0 commit comments

Comments
 (0)