Logging #
We can’t fix what we can’t see. Logging is the most fundamental aspect of observability in how our applications run so that we fix a problem, even proactively. For this, we rely on something more sophisticated than simply logging into the database or syslog. Our tool of choice for this purpose is Sentry.
Any application that you build must be configured to write logs to Sentry. This is fairly straightforward as Sentry has SDKs in a number of languages and frameworks. For Drupal, use the Raven module to pull in the integration and also configure what should be logged.
Sentry Setup #
We need to create a project on Sentry and then use the details to set up the integration.
Routine Monitoring #
Monitoring Alerts in Sentry #
-
Access the Issues Dashboard:
- Use the Issues tab in Sentry to view all logged errors and alerts. This dashboard provides a comprehensive overview of all logged events, grouped by the type and frequency of occurrence.
-
Set Up Alert Rules:
- Navigate to Project Settings > Alerts to configure alert rules and receive notifications for specific issues. Define conditions such as event frequency, error severity, and affected users.
- Set up alerts to notify you when an issue is seen more than 30 times per hour. They can create more alerts as needed.
For more details, refer to the Sentry Alert Rules Documentation.
Configure Slack Notifications #
Follow the Sentry Slack Integration Documentation to set up a Slack notification. Use your project’s #eng-
channel or #feed-
channel to send notifications. In case you’re not sure which channel to use, check with the team.
Creating Tickets from Alerts #
-
Review the Alert Details:
- Access the alert details page to view detailed information, including stack traces, affected users, and the frequency of occurrences. This detailed context helps in understanding the issue better and aids in faster resolution.
- Error Context: Review the contextual data provided by Sentry, such as the environment (production, staging), user actions leading to the error, and system state. This information is critical for diagnosing and resolving issues efficiently. For more details, refer to the Sentry Issue Details Documentation.
-
Integrate Sentry with Your Ticketing System (e.g., Jira, GitHub Issues):
- Select the ticketing system (in our case commonly - Jira) in the Project Settings > Integrations to integrate Sentry with your ticketing system. Follow the prompts to authenticate and authorize Sentry to access your Jira instance. It is vital to Configure the integration settings, such as default project and issue type, to streamline ticket creation. For more details, refer to the Sentry Jira Integration Documentation.
-
Create a Ticket:
-
Manually Creating a Ticket:
- Create an Issue in the alert details view to manually create a ticket by writing all relevant information provided by Sentry to ensure the issue is well-documented.
-
Automatically Creating Tickets:
- Configure automatic ticket creation in Project Settings > Alerts by setting up alert rules to trigger ticket creation by specifying the conditions (e.g., error type, frequency) and actions (create a Jira ticket) for automatic ticket creation.
-
-
Managing Tickets in Jira:
- Ensure tickets are assigned to the appropriate team or individual in Jira. Use Jira’s workflow management tools to track the progress of the ticket from creation to resolution.
- Tracking and Reporting: Use Jira’s reporting features to track the status of logged issues. Generate reports to identify trends, recurring issues, and areas for improvement.
- Comments and Updates: Utilize Jira’s commenting system to add updates, discuss potential solutions, and collaborate with team members directly within the ticket.
Things to Remember #
We apply these practices to ensure effective logging, monitoring, and incident management in our Drupal applications:
- Log significant user actions and interactions using Drupal’s built-in functions and custom modules.
- Disable the Database Logging module (
dblog
) and enable thesyslog
module insettings.php
for efficient logging. - Log critical API requests, responses, and third-party service interactions using techniques such as middleware to capture failed requests and significant events.
- For Sentry, set the logging threshold to Error or Critical to filter and prioritize issues effectively and avoid sending debug and info messages.
- Schedule regular log review sessions with the team to identify and address recurring issues.
- Fine-tune alert rules to minimize noise and focus on critical issues.
- Continuously monitor and adjust alert rules based on feedback and changing application behavior.
- Use Sentry’s integration capabilities to automatically create tickets for high-priority issues.
- Explore automation tools to manage alerts and tickets, including auto-assigning and status updates.
- Develop and maintain incident response plans, conducting regular drills and reviews.