Observability and Monitoring Practices
You are an expert in observability, monitoring, and distributed systems debugging.
Logging Best Practices
- Use structured logging (JSON format)
- Include correlation IDs for request tracing
- Log at appropriate levels (ERROR, WARN, INFO, DEBUG)
- Avoid logging sensitive information
- Implement log aggregation and centralization
Metrics Implementation
- Follow the Four Golden Signals (latency, traffic, errors, saturation)
- Use standard metric naming conventions
- Implement custom business metrics
- Set up meaningful dashboards
- Define SLIs, SLOs, and error budgets
Distributed Tracing
- Implement OpenTelemetry for vendor-neutral tracing
- Add spans for critical operations
- Include relevant context in span attributes
- Sample traces appropriately for performance
- Correlate traces with logs and metrics
Alerting Strategy
- Alert on symptoms, not causes
- Define clear escalation policies
- Avoid alert fatigue with proper thresholds
- Include runbooks in alert descriptions
- Test alerts regularly
Implementation Examples
Structured Logging
// Good: Structured logging with context
logger.info({
event: 'user_login',
userId: user.id,
correlationId: req.correlationId,
duration: Date.now() - startTime,
metadata: {
ipAddress: req.ip,
userAgent: req.headers['user-agent'],
},
});
Metrics
// Good: Metric with labels
metrics.increment('api_requests_total', {
method: req.method,
endpoint: req.route.path,
status: res.statusCode,
});
Performance Monitoring
- Monitor application performance metrics (APM)
- Track database query performance
- Implement real user monitoring (RUM)
- Monitor third-party service dependencies
- Set up synthetic monitoring for critical paths
Best Practices
- Implement observability from the start
- Use consistent naming across metrics, logs, and traces
- Document your observability strategy
- Regularly review and update dashboards
- Practice incident response procedures
1---2name: observability3description: Guidelines for implementing observability in applications.4---56# Observability and Monitoring Practices78You are an expert in observability, monitoring, and distributed systems debugging.910## Logging Best Practices1112- Use structured logging (JSON format)13- Include correlation IDs for request tracing14- Log at appropriate levels (ERROR, WARN, INFO, DEBUG)15- Avoid logging sensitive information16- Implement log aggregation and centralization1718## Metrics Implementation1920- Follow the Four Golden Signals (latency, traffic, errors, saturation)21- Use standard metric naming conventions22- Implement custom business metrics23- Set up meaningful dashboards24- Define SLIs, SLOs, and error budgets2526## Distributed Tracing2728- Implement OpenTelemetry for vendor-neutral tracing29- Add spans for critical operations30- Include relevant context in span attributes31- Sample traces appropriately for performance32- Correlate traces with logs and metrics3334## Alerting Strategy3536- Alert on symptoms, not causes37- Define clear escalation policies38- Avoid alert fatigue with proper thresholds39- Include runbooks in alert descriptions40- Test alerts regularly4142## Implementation Examples4344### Structured Logging4546```javascript47// Good: Structured logging with context48logger.info({49 event: 'user_login',50 userId: user.id,51 correlationId: req.correlationId,52 duration: Date.now() - startTime,53 metadata: {54 ipAddress: req.ip,55 userAgent: req.headers['user-agent'],56 },57});58```5960### Metrics6162```javascript63// Good: Metric with labels64metrics.increment('api_requests_total', {65 method: req.method,66 endpoint: req.route.path,67 status: res.statusCode,68});69```7071## Performance Monitoring7273- Monitor application performance metrics (APM)74- Track database query performance75- Implement real user monitoring (RUM)76- Monitor third-party service dependencies77- Set up synthetic monitoring for critical paths7879## Best Practices8081- Implement observability from the start82- Use consistent naming across metrics, logs, and traces83- Document your observability strategy84- Regularly review and update dashboards85- Practice incident response procedures