Logs
Sentry logs provide structured, searchable logging with automatic correlation to traces and errors.Setup
Enable logs in your SDK initialization:Capturing Logs
Use the logger API to send structured logs:Logs require the
enableLogs option to be set to true during initialization.Log Attributes
Add structured data to logs:Template Strings
Use template strings for structured logging:Log with Scope
Capture logs with specific scope:Log Levels
- trace: Very detailed diagnostic information
- debug: Detailed information for debugging
- info: General informational messages
- warn: Warning messages for potentially harmful situations
- error: Error events
- fatal: Very severe error events that might lead to application abort
Metrics
Custom metrics help you track business and technical KPIs.Counters
Increment counters for counting events:Gauges
Record current values:Distributions
Record value distributions for statistical analysis:Metric Units
Use standard units for better visualization:Correlation with Traces
Logs and metrics are automatically correlated with active spans:Logs and metrics captured within a span are automatically tagged with the trace ID and span ID.
Practical Examples
API Monitoring
Database Operations
Business Metrics
Resource Monitoring
Error Rate Tracking
Scope Integration
Logs and metrics respect scope attributes:Best Practices
Logs
- Use appropriate levels: Match severity to importance
- Add context: Include relevant attributes
- Use structured data: Avoid string concatenation
- Avoid sensitive data: Don’t log PII or secrets
- Use templates: For better grouping
Metrics
- Choose the right type: Counter, gauge, or distribution
- Use consistent names: Follow naming conventions
- Add relevant attributes: For filtering and grouping
- Use standard units: For better visualization
- Don’t over-instrument: Focus on meaningful metrics
Viewing Logs and Metrics
In Sentry:- Logs Explorer: Search and filter logs
- Metrics Dashboard: Visualize custom metrics
- Trace View: See logs/metrics within traces
- Correlation: Link logs/metrics to errors
Next Steps
Performance
Monitor application performance
Tracing
Correlate logs with traces
Error Monitoring
Link errors with logs
Scopes
Manage scope attributes