Skip to content

Add error logging for feedback email sending issue#419

Merged
belwalshubham merged 2 commits intodevelopfrom
fix/email-logging-feedback-issue
Nov 6, 2024
Merged

Add error logging for feedback email sending issue#419
belwalshubham merged 2 commits intodevelopfrom
fix/email-logging-feedback-issue

Conversation

@belwalshubham
Copy link
Copy Markdown
Collaborator

@belwalshubham belwalshubham commented Nov 6, 2024

  • Added error logging to track and debug issues with feedback emails not being sent in the production environment.

Summary by CodeRabbit

  • New Features

    • Enhanced logging for email triggers in the Dropping Center feedback process.
    • Improved logging for metadata retrieval and processing in the Feedback Dropping Center cron function.
  • Bug Fixes

    • Enhanced error handling by including more context in error logs.

These updates improve traceability and debugging capabilities for users interacting with the Dropping Center functionalities.

@belwalshubham belwalshubham self-assigned this Nov 6, 2024
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 6, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes in this pull request enhance logging capabilities within the DroppingCenterFeedbackService and FeedbackDroppingCenterCron components. A logging statement was added to the processDroppingCenterStatus method to indicate when an email trigger occurs. In the feedback_dropping_center_cron function, modifications were made to the entity retrieval behavior and additional logging statements were introduced to capture relevant metadata and error context. Overall, these changes improve traceability and debugging without altering existing functionality.

Changes

File Change Summary
wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterFeedbackService.php Added logging in processDroppingCenterStatus to indicate when an email trigger occurs and when feedback email delivery status is updated.
wp-content/civi-extensions/goonjcustom/api/v3/Goonjcustom/FeedbackDroppingCenterCron.php Modified civicrm_api3_goonjcustom_feedback_dropping_center_cron to change parameter behavior, added logging for metadata retrieval and processing, and enhanced error logging with context.

Possibly related PRs

Suggested labels

status : ready for review

Suggested reviewers

  • tarunnjoshi
  • pokhiii

🎉 In the code where feedback flows,
Logging now tracks where the email goes.
With each status and ID in sight,
Debugging's clearer, making it right.
So here's to the logs, both big and small,
Enhancing our code, we celebrate all! 🎊


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@tarunnjoshi
Copy link
Copy Markdown
Member

tarunnjoshi commented Nov 6, 2024

Add one simple log below the update query
// Update status if the email is sent. EckEntity::update('Dropping_Center_Meta', TRUE) ->addValue('Status.Feedback_Email_Delivered', 1) ->addWhere('Dropping_Center_Meta.Dropping_Center', '=', $droppingCenterId) ->execute(); }

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (4)
wp-content/civi-extensions/goonjcustom/api/v3/Goonjcustom/FeedbackDroppingCenterCron.php (2)

68-74: Consider using debug level for detailed logging

While the detailed logging is valuable for troubleshooting, consider using debug level for per-record details in production:

-      Civi::log()->info('Dropping Center Meta details', [
+      Civi::log()->debug('Dropping Center Meta details', [

Line range hint 82-83: Enhance error handling granularity and structure

The current error handling could be improved in several ways:

  1. Move try-catch inside the loop to handle each dropping center independently
  2. Use structured logging for errors
-  catch (Exception $e) {
-    \CRM_Core_Error::debug_log_message('Error processing Dropping Center ID: ' . $droppingCenterId . ' - ' . $e->getMessage());
+  catch (Exception $e) {
+    Civi::log()->error('Failed to process dropping center feedback', [
+      'dropping_center_id' => $droppingCenterId,
+      'initiator_id' => $initiatorId,
+      'error' => $e->getMessage(),
+      'trace' => $e->getTraceAsString(),
+    ]);
wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterFeedbackService.php (2)

Line range hint 36-45: Add error handling around email operations.

The email sending and status update operations lack error handling, which could lead to silent failures in production. This makes it difficult to track and debug issues when they occur.

Consider wrapping these operations in try-catch blocks with proper error logging:

+      try {
         self::sendFeedbackEmail($organizingContactName, $droppingCenterId, $contactEmailId, $from);
+      } catch (\Exception $e) {
+        Civi::log()->error('Failed to send feedback email', [
+          'dropping_center_id' => $droppingCenterId,
+          'initiator_id' => $initiatorId,
+          'error' => $e->getMessage(),
+          'trace' => $e->getTraceAsString()
+        ]);
+        throw $e;
+      }

+      try {
         // Update status if the email is sent.
         EckEntity::update('Dropping_Center_Meta', TRUE)
           ->addValue('Status.Feedback_Email_Delivered', 1)
           ->addWhere('Dropping_Center_Meta.Dropping_Center', '=', $droppingCenterId)
           ->execute();
+        Civi::log()->info('Successfully updated feedback email status', [
+          'dropping_center_id' => $droppingCenterId
+        ]);
+      } catch (\Exception $e) {
+        Civi::log()->error('Failed to update feedback email status', [
+          'dropping_center_id' => $droppingCenterId,
+          'error' => $e->getMessage()
+        ]);
+        throw $e;
+      }

Line range hint 89-93: Add logging in sendFeedbackEmail method.

The email sending method should include logging to track successful email delivery.

Consider adding a success log after email sending:

     // Send the email.
     \CRM_Utils_Mail::send($mailParams);
+    Civi::log()->info('Successfully sent feedback email', [
+      'recipient' => $contactEmailId,
+      'dropping_center_id' => $droppingCenterId
+    ]);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6ededc4 and 9bc2865.

📒 Files selected for processing (2)
  • wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterFeedbackService.php (1 hunks)
  • wp-content/civi-extensions/goonjcustom/api/v3/Goonjcustom/FeedbackDroppingCenterCron.php (2 hunks)
🔇 Additional comments (1)
wp-content/civi-extensions/goonjcustom/api/v3/Goonjcustom/FeedbackDroppingCenterCron.php (1)

49-54: Verify the impact of disabling caching in EckEntity::get

The change from TRUE to FALSE in EckEntity::get() disables caching. While this ensures fresh data, it might impact performance if this cron runs frequently with large datasets.

✅ Verification successful

Based on the shell script results, I can now provide a final response:

Disabling caching in EckEntity::get is consistent with codebase patterns

Looking at the codebase usage patterns of EckEntity::get(), the caching parameter (TRUE/FALSE) is consistently chosen based on the use case:

  • Caching is disabled (FALSE) when retrieving data that needs to be fresh, especially in user-facing operations and data mutations
  • Caching is enabled (TRUE) for background operations like cron jobs that process bulk data

In this case, disabling caching for feedback email delivery status is appropriate since:

  1. The feedback status needs to be accurate and fresh to avoid duplicate emails
  2. The query is targeted with specific conditions, so performance impact is minimal
  3. Other similar feedback-related cron jobs in the codebase also use caching strategically
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for other instances of EckEntity::get to understand caching patterns
rg -A 2 "EckEntity::get\\(" --type php

# Look for cron schedule configuration
fd -e php -e json -H cron

Length of output: 19594

Comment on lines +55 to +58
Civi::log()->info('Dropping Center Meta data retrieved', [
'status_name' => $statusName,
'data' => $droppingCenterMeta,
]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider logging volume and data sensitivity

The current logging statement dumps the entire $droppingCenterMeta dataset, which could:

  1. Generate excessive log volume in production
  2. Potentially expose sensitive contact information

Consider logging only essential metadata:

-    'data' => $droppingCenterMeta,
+    'count' => count($droppingCenterMeta),
+    'dropping_center_ids' => array_column($droppingCenterMeta, 'Dropping_Center_Meta.Dropping_Center'),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Civi::log()->info('Dropping Center Meta data retrieved', [
'status_name' => $statusName,
'data' => $droppingCenterMeta,
]);
Civi::log()->info('Dropping Center Meta data retrieved', [
'status_name' => $statusName,
'count' => count($droppingCenterMeta),
'dropping_center_ids' => array_column($droppingCenterMeta, 'Dropping_Center_Meta.Dropping_Center'),
]);

Comment on lines +35 to +36
Civi::log()->info('trigger email');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance logging with contextual information.

The current logging statement is too basic and lacks important context that would be valuable for debugging production issues.

Consider enhancing the log message with relevant metadata:

-      Civi::log()->info('trigger email');
+      Civi::log()->info('Triggering feedback email', [
+        'dropping_center_id' => $droppingCenterId,
+        'initiator_id' => $initiatorId,
+        'recipient_email' => $contactEmailId,
+        'recipient_name' => $organizingContactName
+      ]);

Committable suggestion skipped: line range outside the PR's diff.

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