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