Ajout d'un système de signalisation de bugs automatiser et manuel
This commit is contained in:
parent
99ab16098f
commit
88aa73cda9
9 changed files with 1345 additions and 7 deletions
|
|
@ -45,7 +45,52 @@ class KubyLogger:
|
|||
)
|
||||
audit_handler.setFormatter(audit_formatter)
|
||||
self.logger.addHandler(audit_handler)
|
||||
|
||||
|
||||
# GitLab handler for automated error reporting
|
||||
try:
|
||||
from utils.gitlab_client import gitlab_client
|
||||
class GitLabHandler(logging.Handler):
|
||||
def __init__(self, client):
|
||||
super().__init__()
|
||||
self.client = client
|
||||
self.last_errors = {}
|
||||
self.cooldown = 3600 # 1 hour cooldown per unique error
|
||||
|
||||
def emit(self, record):
|
||||
if record.levelno >= logging.ERROR:
|
||||
# Extract message and first line of traceback if available
|
||||
msg = record.getMessage()
|
||||
error_key = msg
|
||||
if record.exc_info:
|
||||
error_key += str(record.exc_info[1])
|
||||
|
||||
current_time = time.time()
|
||||
if error_key in self.last_errors and current_time - self.last_errors[error_key] < self.cooldown:
|
||||
return # Skip if same error within cooldown
|
||||
|
||||
self.last_errors[error_key] = current_time
|
||||
|
||||
# Create issue (Fire and forget, we don't want to block logging)
|
||||
description = f"**Type:** {record.levelname}\n"
|
||||
description += f"**Message:** {msg}\n"
|
||||
description += f"**Source:** {record.name}.{record.funcName}:{record.lineno}\n\n"
|
||||
if record.exc_info:
|
||||
description += f"**Traceback:**\n```python\n{traceback.format_exc()}\n```"
|
||||
|
||||
title = f"[AUTO] Error: {msg[:50]}..."
|
||||
loop = asyncio.get_event_loop()
|
||||
if loop.is_running():
|
||||
loop.create_task(self.client.create_issue(title, description, labels=["bug", "auto-report"]))
|
||||
else:
|
||||
# Fallback if loop is not running (rare for this bot)
|
||||
pass
|
||||
|
||||
gitlab_handler = GitLabHandler(gitlab_client)
|
||||
gitlab_handler.setLevel(logging.ERROR)
|
||||
self.logger.addHandler(gitlab_handler)
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to initialize GitLabHandler: {e}")
|
||||
|
||||
def debug(self, message, **kwargs):
|
||||
self.logger.debug(message, **kwargs)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue