Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve logging messages #298

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

attiyaIshaque
Copy link
Member

Merge checklist:
Check off if complete or not applicable:

  • Documentation updated (not only docstrings)
  • Fixup commits are squashed away
  • Unit tests added/updated
  • Manual testing instructions provided
  • Noted any: Concerns, dependencies, migration issues, deadlines, tickets

Post-merge:

@attiyaIshaque attiyaIshaque force-pushed the attiya/SONIC-745-improve-logging branch 3 times, most recently from 0b926dc to 375eabe Compare November 21, 2024 12:17
Copy link

github-actions bot commented Nov 21, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  commerce_coordinator/apps/commercetools
  tasks.py
  commerce_coordinator/apps/commercetools/tests
  test_tasks.py
  commerce_coordinator/apps/core
  clients.py
  commerce_coordinator/apps/lms
  clients.py
  tasks.py
Project Total  

This report was generated by python-coverage-comment-action

@attiyaIshaque attiyaIshaque force-pushed the attiya/SONIC-745-improve-logging branch from 375eabe to cd07f5d Compare November 21, 2024 12:33
@attiyaIshaque attiyaIshaque force-pushed the attiya/SONIC-745-improve-logging branch 3 times, most recently from 96bc7d1 to 2598127 Compare November 25, 2024 13:33
Copy link
Member

@aht007 aht007 left a comment

Choose a reason for hiding this comment

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

I see in the ticket ACs that we had to add appropriate errors such as CommerceToolsError to retries where needed. Have we verified that we don't need to change anything related to this?
Note for merging: please ensure on staging that we get appropriate error badges on DataDog.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need log messages at the start and end of every operation. In my opinion this will just pollute the logging information. Mostly we use this approach for debugging some issues but in normal cases I wouldn't suggest adding this many logs

Copy link
Member

Choose a reason for hiding this comment

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

Please also make appropriate changes elsewhere in the PR where needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I have added the CommerceToolsError in the appropriate places where retries are needed. As for the error badges, I've ensured that the log messages are structured correctly, first showing info and then debug. I will also verify on staging to ensure that the appropriate error badges are showing up on DataDog as expected before merging.

Copy link
Member

Choose a reason for hiding this comment

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

This comment still needs resolution: Reference

Copy link
Member

@aht007 aht007 Dec 10, 2024

Choose a reason for hiding this comment

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

Also i am not sure if I see any new error being added to retry cases. You might need to look into that as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have checked, and we don't need any new errors.

logger.error(f"Unable to update line item [ {line_item_id} ] state on fulfillment "
f"result with error {err.errors} and correlation id {err.correlation_id}")
logger.error(f"[update_line_item_state] Failed to update line item {line_item_id} for order {order_id}. "
f"Error: {err.errors}, Correlation ID: {err.correlation_id}")
Copy link
Member

Choose a reason for hiding this comment

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

Can we make this a continuous line instead.

Suggested change
f"Error: {err.errors}, Correlation ID: {err.correlation_id}")
f"with error: {err.errors}, Correlation ID: {err.correlation_id}")

Copy link
Member

Choose a reason for hiding this comment

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

Please use continuous lines for logs elsewhere in the PR too

Copy link
Member

Choose a reason for hiding this comment

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

This still needs resolution elsewhere. Please use the same approach in the whole PR.

commerce_coordinator/apps/core/clients.py Outdated Show resolved Hide resolved
commerce_coordinator/apps/lms/tasks.py Outdated Show resolved Hide resolved
@attiyaIshaque attiyaIshaque force-pushed the attiya/SONIC-745-improve-logging branch from 2598127 to a35b631 Compare December 5, 2024 12:04
ext_logger.debug('Request headers: %s', response.request.headers)
ext_logger.debug('Response status: %s %s', response.status_code, response.reason)
ext_logger.debug('Response text: %s', response.text)
# Extract request details and response information
Copy link
Member

Choose a reason for hiding this comment

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

Please remove these comments where added. We don't add this much comments in the codebase

ext_logger.debug('Response status: %s %s', response.status_code, response.reason)
ext_logger.debug('Response text: %s', response.text)
# Extract request details and response information
request_url = response.request.url
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to make separate variables for all these?
These can simply be used directly in the log message.
Same comment for the below changes as well

f"course id: {logging_obj['course_id']}, message_id: {logging_obj['message_id']}, "
f"celery_task_id: {logging_obj['celery_task_id']}]"
f"[LMSAPIClient] Successful fulfillment for user '{logging_obj['user']}'. "
f"Details: [LMS User ID: {logging_obj['lms_user_id']}, Order ID: {logging_obj['order_id']}, "
Copy link
Member

Choose a reason for hiding this comment

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

Please use the field names itself in the log messages. This is an improvement to the already existing log messages since they are also not using the field names for logging which makes it difficult to follow the logs.
Example:
If we are logging lms_user_id in logs then it's log should also log the same field name lms_user_id and not lms user id or LMS User ID

Suggested change
f"Details: [LMS User ID: {logging_obj['lms_user_id']}, Order ID: {logging_obj['order_id']}, "
f"Details: [lms_user_id: {logging_obj['lms_user_id']}, Order ID: {logging_obj['order_id']}, "

@aht007
Copy link
Member

aht007 commented Dec 10, 2024

Please take a look into this recommendation from @shafqatfarhan as well: https://twou.slack.com/archives/C07UZC8DDSR/p1733148401861559

@attiyaIshaque attiyaIshaque force-pushed the attiya/SONIC-745-improve-logging branch from a35b631 to 5a68365 Compare December 12, 2024 09:22
@attiyaIshaque
Copy link
Member Author

Please take a look into this recommendation from @shafqatfarhan as well: https://twou.slack.com/archives/C07UZC8DDSR/p1733148401861559

I have addressed this in this PR.

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.

3 participants