domains / / the-pr-agent/pr-agent
Logging consistency and safety
When writing/adjusting code, treat logging as part of error handling: - Use the right level: log request- or operation-failure conditions at `error`/`exception` (not `warning`).
When writing/adjusting code, treat logging as part of error handling:
- Use the right level: log request- or operation-failure conditions at
error/exception(notwarning). - In
exceptblocks, preferget_logger().exception(...)(orerror(...)) and include identifying context (IDs, URLs, comment_id, PR/issue number) so logs are traceable. - Use structured/context fields (e.g.,
artifact={...}) rather than passing arbitrary objects (like dicts) as separate arguments to the logger—this can cause formatting/type issues. - Avoid
printstatements for debug; useget_logger().debug(...)with the same context. - Don’t comment out logging used for exception diagnostics—either log it or remove the dead code.
Example pattern:
try:
...
except Exception as e:
get_logger().exception(
"Failed to publish inline code comments fallback",
artifact={
"comment_id": comment_id,
"error": repr(e),
"pr_number": pr_number,
},
)
raise
For non-exception unexpected formats:
get_logger().warning(
"Unexpected response format",
artifact={"response": str(response_tuple)},
)