How Can I Manage Logs and Metrics Ingestion in Sentry.io?
Sentry.io provides flexible options for managing logs and metrics ingestion, allowing users to control what data is sent to the platform. This article outlines methods to filter or disable logs and metrics while maintaining error and trace reporting.
Overview of Log and Metric Management
Sentry.io does not offer a built-in setting to automatically stop ingesting specific errors or logs after a fixed number of occurrences. However, users can leverage SDK configurations and project settings to manage logs and metrics effectively. These methods include filtering logs before they are sent or dropping logs and metrics entirely.
SDK-Based Filtering and Configuration
To filter logs and metrics at the SDK level, you can use the following configurations:
1. Filter Logs Using beforeSendLog: Add a beforeSendLog hook to your SDK configuration to drop specific log messages before they are sent to Sentry. Return null to drop a log, or return the log to send it. For example:
Sentry.init({
beforeSendLog: (log) => (/specific-pattern/.test(log.message) ? null : log),
});2. Disable Metrics and Logs in the JavaScript SDK: If you are using Sentry JavaScript SDK v10.25.0 or later, you can disable logs and metrics while keeping errors and traces:
Sentry.init({
beforeSendLog: () => null,
beforeSendMetric: () => null,
});This configuration prevents logs and metrics from being sent while leaving error and trace events unaffected. Note that on versions below 11.0.0 you can alternatively set enableMetrics: false, and logs stay off until you set enableLogs: true (before 10.71.0). Both options were removed in 11.0.0, so beforeSendLog and beforeSendMetric are the way to drop them there.
Project Settings for Inbound Filtering
Sentry also allows you to filter logs at the project level using inbound filters. This method is quicker to configure and does not require SDK changes. Custom log message filters are available on Trial, Business, and Enterprise plans:
Navigate to Project Settings → Inbound Filters.
Add a filter for specific log messages. Filters use case-insensitive glob patterns (not regex), so use wildcards, for example *ENOSPC: no space left on device*, to discard matching logs.
This approach ensures that matching logs are discarded before they count against your quota. SDK-side filtering offers finer control, but inbound filtering is a simpler alternative.
Best Practices
Use SDK-based filtering for fine-grained control over logs and metrics.
Leverage inbound filters for quick and easy configuration.
Regularly review your filters to ensure they align with your current needs.
By combining these methods, you can effectively manage logs and metrics ingestion in Sentry.io, optimizing your data usage and focusing on the most critical events.
