Skill 100 · Troubleshooting Application Failures
Subchapter 100.1
references/application-failure-troubleshooting.mdMarkdown16 KBView on GitHub
This SOP provides comprehensive troubleshooting for failing applications through CloudWatch log analysis. It discovers log groups related to the application name, searches for error patterns, analyzes stack traces and exceptions, and provides specific recommendations based on the findings in the logs.
Prompt the user in a single message to provide all required parameters at once. Clearly list the required parameters and their descriptions, and include any optional parameters with their default values. Do not proceed until you have received and confirmed all required parameters. If any required parameter is missing or unclear, you MUST explicitly request the missing information before moving forward.
Only proceed to the steps below if you have all required information.
Check for required tools and warn the user if any are missing.
Constraints:
Search for CloudWatch log groups that are related to the application name.
Constraints:
aws logs describe-log-groups --region ${region}/aws/lambda/*${application_name}*/aws/apigateway/*${application_name}*/aws/ecs/*${application_name}*/aws/applicationelb/*${application_name}**${application_name}* (custom application log groups)Verify the selected log groups exist and determine the available time range for analysis.
Constraints:
aws logs describe-log-groups --log-group-name-prefix ${log_group_name} --region ${region}aws logs describe-log-streams --log-group-name ${log_group_name} --order-by LastEventTime --descending --max-items 10 --region ${region}lastEventTimestamp from log streams to determine the most recent activitySearch CloudWatch logs for error patterns and failure indicators.
Constraints:
lastEventTimestamp from the log streams as the reference point for time calculationslastEventTimestamp from the log streams response (step 3)aws logs start-query --log-group-name ${log_group_name} --start-time ${start_timestamp} --end-time ${end_timestamp} --query-string 'fields @timestamp, @message | filter @message like /(?i)(error|fail|exception|timeout|unable|denied|invalid)/ | sort @timestamp desc | limit 100' --region ${region}aws logs start-query --log-group-name ${log_group_name} --start-time ${start_timestamp} --end-time ${end_timestamp} --query-string 'fields @timestamp, @message | filter @message like /(?i)(exception|stack trace|caused by|at .+\\.java:|at .+\\.py:)/ | sort @timestamp desc | limit 100' --region ${region}Poll for completion and retrieve results from all CloudWatch Logs queries.
Constraints:
aws logs get-query-results --query-id ${query_id} --region ${region}Analyze the collected log data to identify error patterns, frequency, and trends.
Constraints:
Identify the most likely root causes based on all collected evidence.
Constraints:
Develop specific, prioritized recommendations to resolve the application failures.
Constraints:
Create a detailed troubleshooting report with findings and recommendations.
Constraints:
application_name: payment-service
region: us-west-2
time_window_hours: 4# Application Failure Troubleshooting Report
**Application:** payment-service
**Region:** us-west-2
**Analysis Period:** Last 4 hours
## Executive Summary
- 847 errors detected across 3 log groups in the last 4 hours
- Peak error period: 2:15 PM - 2:45 PM UTC
- Primary root cause: Connection pool exhaustion (67% of errors)
- Secondary cause: Unhandled NullPointerException in validation (23% of errors)
- Tertiary cause: External service timeout (10% of errors)
## Log Groups Analyzed
- **/aws/lambda/payment-service-processor**: 456 errors (Lambda function logs)
- **/aws/lambda/payment-service-validator**: 234 errors (Validation service logs)
- **/payment-service/application**: 157 errors (Custom application logs)
## Error Pattern Analysis
### Error Frequency and Trends
- **Total errors**: 847 across all log groups
- **Error spike**: 2:15 PM - 2:45 PM (423 errors in 30 minutes)
- **Baseline errors**: 15-20 errors per hour outside spike period
- **Most affected component**: payment-service-processor (54% of errors)
### Specific Error Messages Found
1. **Connection Pool Exhaustion** (567 occurrences - 67%):ERROR: could not obtain a database connection within 30 seconds java.sql.SQLException: Connection pool exhausted at com.payment.db.ConnectionManager.getConnection(ConnectionManager.java:45)
2. **Null Pointer Exception in Validation** (198 occurrences - 23%):ERROR: NullPointerException in payment validation java.lang.NullPointerException: Cannot invoke “PaymentRequest.getAmount()” because “request” is null at com.payment.validator.PaymentValidator.validate(PaymentValidator.java:23)
3. **External Service Timeout** (82 occurrences - 10%):ERROR: Payment gateway timeout after 30 seconds java.net.SocketTimeoutException: Read timed out at com.payment.gateway.StripeClient.processPayment(StripeClient.java:67)
## Root Cause Analysis
### Primary Cause: Connection Pool Exhaustion
- **Evidence**: 567 "Connection pool exhausted" errors in logs, concentrated during traffic spike
- **Impact**: High - affects 67% of all errors
- **Urgency**: Critical - immediate action required
- **Location**: ConnectionManager.java:45 in payment-service-processor
### Secondary Cause: Null Pointer Exception in Validation
- **Evidence**: 198 NullPointerException errors when PaymentRequest.getAmount() is called on null object
- **Impact**: Medium - affects 23% of errors
- **Urgency**: High - code fix needed
- **Location**: PaymentValidator.java:23 in payment-service-validator
### Tertiary Cause: External Service Timeouts
- **Evidence**: 82 SocketTimeoutException errors from external API calls
- **Impact**: Low - affects 10% of errors
- **Urgency**: Medium - configuration and retry logic needed
- **Location**: StripeClient.java:67 in payment-service-processor
## Action Plan
### Immediate Actions
1. **Increase Connection Pool Size**:
- Update ConnectionManager configuration to increase max connections from 20 to 50
- Add connection pool monitoring and alerting
- Deploy configuration change immediately
2. **Add Null Check in Validator**:
```java
// Fix in PaymentValidator.java:23
public void validate(PaymentRequest request) {
if (request == null) {
throw new IllegalArgumentException("PaymentRequest cannot be null");
}
// existing validation logic...
}CloudWatch Log Alarms:
Custom Metrics: Create custom metrics from log patterns for real-time monitoring
## Troubleshooting
### No Log Groups Found
If no log groups are discovered for the application name, ask the user to provide specific log group names. Common patterns include `/aws/lambda/function-name`, `/aws/apigateway/api-name`, or custom application log groups.
### No Logs Available
If CloudWatch logs are empty, check if logging is enabled for the application. Verify that the application is actually running and generating logs during the specified time window.
### Access Denied Errors
Verify AWS credentials have permissions for CloudWatch Logs service, specifically `logs:DescribeLogGroups`, `logs:DescribeLogStreams`, `logs:StartQuery`, and `logs:GetQueryResults`.
### High Volume Log Analysis
For applications with high log volumes, consider using shorter time windows (1-2 hours) or more specific log queries to avoid timeouts and improve performance.
### Query Timeouts
If CloudWatch Logs Insights queries timeout, reduce the time window or limit the number of results. Large log groups may require multiple smaller queries.
### Multi-Region Applications
For applications spanning multiple regions, run the analysis in each region separately since CloudWatch Logs are region-specific.
### Log Retention Issues
If the requested time window exceeds log retention settings, adjust the analysis period to fit within the available log data range.