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: observability-23description: 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 Logging45```javascript46// Good: Structured logging with context47logger.info({48 event: 'user_login',49 userId: user.id,50 correlationId: req.correlationId,51 duration: Date.now() - startTime,52 metadata: {53 ipAddress: req.ip,54 userAgent: req.headers['user-agent']55 }56});57```5859### Metrics60```javascript61// Good: Metric with labels62metrics.increment('api_requests_total', {63 method: req.method,64 endpoint: req.route.path,65 status: res.statusCode66});67```6869## Performance Monitoring7071- Monitor application performance metrics (APM)72- Track database query performance73- Implement real user monitoring (RUM)74- Monitor third-party service dependencies75- Set up synthetic monitoring for critical paths7677## Best Practices7879- Implement observability from the start80- Use consistent naming across metrics, logs, and traces81- Document your observability strategy82- Regularly review and update dashboards83- Practice incident response procedures