mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-01 19:30:40 +08:00
Add analytics logging
This commit is contained in:
@ -74,6 +74,7 @@ class PRAgent:
|
||||
|
||||
action = action.lstrip("/").lower()
|
||||
with get_logger().contextualize(command=action):
|
||||
get_logger().info("PR-Agent request handler started", analytics=True)
|
||||
if action == "reflect_and_review":
|
||||
get_settings().pr_reviewer.ask_and_reflect = True
|
||||
if action == "answer":
|
||||
|
@ -22,6 +22,10 @@ def analytics_filter(record: dict) -> bool:
|
||||
return record.get("extra", {}).get("analytics", False)
|
||||
|
||||
|
||||
def inv_analytics_filter(record: dict) -> bool:
|
||||
return not record.get("extra", {}).get("analytics", False)
|
||||
|
||||
|
||||
def setup_logger(level: str = "INFO", fmt: LoggingFormat = LoggingFormat.CONSOLE):
|
||||
level: int = logging.getLevelName(level.upper())
|
||||
if type(level) is not int:
|
||||
@ -31,6 +35,7 @@ def setup_logger(level: str = "INFO", fmt: LoggingFormat = LoggingFormat.CONSOLE
|
||||
logger.remove(None)
|
||||
logger.add(
|
||||
sys.stdout,
|
||||
filter=inv_analytics_filter,
|
||||
level=level,
|
||||
format="{message}",
|
||||
colorize=False,
|
||||
@ -38,7 +43,7 @@ def setup_logger(level: str = "INFO", fmt: LoggingFormat = LoggingFormat.CONSOLE
|
||||
)
|
||||
elif fmt == LoggingFormat.CONSOLE: # does not print the 'extra' fields
|
||||
logger.remove(None)
|
||||
logger.add(sys.stdout, level=level, colorize=True)
|
||||
logger.add(sys.stdout, level=level, colorize=True, filter=inv_analytics_filter)
|
||||
|
||||
log_folder = get_settings().get("CONFIG.ANALYTICS_FOLDER", "")
|
||||
if log_folder:
|
||||
|
@ -205,8 +205,9 @@ async def handle_request(body: Dict[str, Any], event: str):
|
||||
return {}
|
||||
agent = PRAgent()
|
||||
sender = body.get("sender", {}).get("login")
|
||||
app_name = get_settings().get("CONFIG.APP_NAME", "Unknown")
|
||||
log_context = {"action": action, "event": event, "sender": sender, "server_type": "github_app",
|
||||
"request_id": uuid.uuid4().hex}
|
||||
"request_id": uuid.uuid4().hex, "app_name": app_name}
|
||||
|
||||
# handle comments on PRs
|
||||
if action == 'created':
|
||||
|
Reference in New Issue
Block a user