Skip to content

Conversation

@mozillazg
Copy link
Contributor

No description provided.

Copilot AI review requested due to automatic review settings October 20, 2025 08:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds consistent error logging for HTTP API failures in the Kagent session service to improve debugging and monitoring capabilities. The changes wrap existing HTTP status error handling with try-catch blocks that log the response text before re-raising the exceptions.

  • Adds error logging for all HTTP API failures in session operations
  • Maintains existing error handling behavior while adding visibility into failure details
  • Uses consistent logging format across all session service methods

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

try:
response.raise_for_status()
except httpx.HTTPStatusError:
logger.error(f"Failed to create session: {response.text}")
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging the full response text could potentially expose sensitive information. Consider logging only the status code and reason phrase, or sanitize the response content before logging.

Suggested change
logger.error(f"Failed to create session: {response.text}")
logger.error(
f"Failed to create session: status_code={response.status_code}, reason={response.reason_phrase}"
)

Copilot uses AI. Check for mistakes.
except httpx.HTTPStatusError as e:
if e.response.status_code == 404:
return None
logger.error(f"Failed to get session: {response.text}")
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging the full response text could potentially expose sensitive information. Consider logging only the status code and reason phrase, or sanitize the response content before logging.

Copilot uses AI. Check for mistakes.
try:
response.raise_for_status()
except httpx.HTTPStatusError:
logger.error(f"Failed to list sessions: {response.text}")
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging the full response text could potentially expose sensitive information. Consider logging only the status code and reason phrase, or sanitize the response content before logging.

Suggested change
logger.error(f"Failed to list sessions: {response.text}")
logger.error(f"Failed to list sessions: status_code={response.status_code}, reason={getattr(response, 'reason_phrase', '')}")

Copilot uses AI. Check for mistakes.
try:
response.raise_for_status()
except httpx.HTTPStatusError:
logger.error(f"Failed to delete session: {response.text}")
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging the full response text could potentially expose sensitive information. Consider logging only the status code and reason phrase, or sanitize the response content before logging.

Copilot uses AI. Check for mistakes.
try:
response.raise_for_status()
except httpx.HTTPStatusError:
logger.error(f"Failed to append event: {response.text}")
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging the full response text could potentially expose sensitive information. Consider logging only the status code and reason phrase, or sanitize the response content before logging.

Copilot uses AI. Check for mistakes.
response.raise_for_status()
try:
response.raise_for_status()
except httpx.HTTPStatusError:
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error handling pattern is duplicated across multiple methods. Consider extracting this into a helper method or decorator to reduce code duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
response.raise_for_status()
try:
response.raise_for_status()
except httpx.HTTPStatusError:
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error handling pattern is duplicated across multiple methods. Consider extracting this into a helper method or decorator to reduce code duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
response.raise_for_status()
try:
response.raise_for_status()
except httpx.HTTPStatusError:
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error handling pattern is duplicated across multiple methods. Consider extracting this into a helper method or decorator to reduce code duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
response.raise_for_status()
try:
response.raise_for_status()
except httpx.HTTPStatusError:
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error handling pattern is duplicated across multiple methods. Consider extracting this into a helper method or decorator to reduce code duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
@peterj
Copy link
Collaborator

peterj commented Oct 20, 2025

thanks for the PR @mozillazg . can you address the copilot comments?

@mozillazg mozillazg changed the title chore(kagent-adk/session_sevice): add logging for Kagent API errors chore(kagent-adk/session_service): add logging for Kagent API errors Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants