Skip to main content
Sentry supports sending structured logs and custom metrics alongside your error and performance data, providing a complete observability solution.

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:
Template strings allow Sentry to group similar log messages together while preserving the actual values.

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

  1. Use appropriate levels: Match severity to importance
  2. Add context: Include relevant attributes
  3. Use structured data: Avoid string concatenation
  4. Avoid sensitive data: Don’t log PII or secrets
  5. Use templates: For better grouping

Metrics

  1. Choose the right type: Counter, gauge, or distribution
  2. Use consistent names: Follow naming conventions
  3. Add relevant attributes: For filtering and grouping
  4. Use standard units: For better visualization
  5. Don’t over-instrument: Focus on meaningful metrics

Viewing Logs and Metrics

In Sentry:
  1. Logs Explorer: Search and filter logs
  2. Metrics Dashboard: Visualize custom metrics
  3. Trace View: See logs/metrics within traces
  4. 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