Class: Findbug::Configuration
- Inherits:
-
Object
- Object
- Findbug::Configuration
- Defined in:
- lib/findbug/configuration.rb
Overview
Configuration holds all settings for Findbug.
WHY THIS PATTERN?
This is the standard Ruby gem configuration pattern. Users call:
Findbug.configure do |config|
config.redis_url = "redis://localhost:6379/1"
config.enabled = Rails.env.production?
end
Benefits:
-
All settings in one place (easy to find/audit)
-
Sensible defaults (works without configuration)
-
Type checking and validation at startup (fail fast)
-
Isolated from global state (each setting is an instance variable)
Instance Attribute Summary collapse
-
#alerts ⇒ Object
readonly
DSL for configuring alerts.
-
#auto_persist ⇒ Object
Whether to use the built-in background persister thread.
-
#buffer_ttl ⇒ Object
Redis key TTL for buffered events (in seconds).
-
#enabled ⇒ Object
Whether Findbug is enabled.
-
#environment ⇒ Object
Environment name override.
-
#ignored_exceptions ⇒ Object
Exception classes to ignore.
-
#ignored_paths ⇒ Object
Paths to ignore (regex patterns).
-
#logger ⇒ Object
Custom logger.
-
#max_buffer_size ⇒ Object
Maximum buffer size in Redis (number of events).
-
#performance_enabled ⇒ Object
Whether to enable performance monitoring (request timing, SQL queries).
-
#performance_sample_rate ⇒ Object
Sample rate for performance monitoring (0.0 to 1.0).
-
#persist_batch_size ⇒ Object
Batch size for persistence job (how many events to move from Redis to DB at once).
-
#persist_interval ⇒ Object
Interval (in seconds) for the background persister thread.
-
#queue_name ⇒ Object
Queue name for Findbug’s background jobs.
-
#redis_pool_size ⇒ Object
Size of the Redis connection pool.
-
#redis_pool_timeout ⇒ Object
Timeout for getting a connection from the pool (in seconds).
-
#redis_url ⇒ Object
Redis connection URL.
-
#release ⇒ Object
Release/version identifier (e.g., git SHA, semantic version).
-
#retention_days ⇒ Object
How many days to keep error/performance data in the database.
-
#sample_rate ⇒ Object
Sample rate for error capture (0.0 to 1.0).
-
#scrub_fields ⇒ Object
Field names to scrub from captured data.
-
#scrub_header_names ⇒ Object
Additional headers to scrub (beyond defaults).
-
#scrub_headers ⇒ Object
Whether to scrub request headers.
-
#slow_query_threshold_ms ⇒ Object
Threshold in ms for flagging slow SQL queries.
-
#slow_request_threshold_ms ⇒ Object
Threshold in ms.
-
#web_password ⇒ Object
Password for basic auth on the dashboard.
-
#web_path ⇒ Object
Path prefix for the dashboard.
-
#web_username ⇒ Object
Username for basic auth on the dashboard.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#should_capture_exception?(exception) ⇒ Boolean
Check if we should capture this exception class.
-
#should_capture_path?(path) ⇒ Boolean
Check if we should capture this request path.
-
#should_capture_performance? ⇒ Boolean
Check if we should capture performance for this request.
-
#validate! ⇒ Object
Validate configuration at startup Raises ConfigurationError if something is wrong.
-
#web_enabled? ⇒ Boolean
Check if the dashboard should be enabled.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/findbug/configuration.rb', line 169 def initialize # Set sensible defaults @enabled = true # Redis defaults - note we use database 1 to avoid conflicts @redis_url = ENV.fetch("FINDBUG_REDIS_URL", "redis://localhost:6379/1") @redis_pool_size = ENV.fetch("FINDBUG_REDIS_POOL_SIZE", 5).to_i @redis_pool_timeout = 1 # Error capture defaults @sample_rate = 1.0 @ignored_exceptions = [] @ignored_paths = [] # Performance defaults @performance_enabled = true @performance_sample_rate = 0.1 @slow_request_threshold_ms = 0 @slow_query_threshold_ms = 100 # Security defaults - these are CRITICAL @scrub_fields = %w[ password password_confirmation secret secret_key secret_token api_key api_secret access_token refresh_token credit_card card_number cvv ssn social_security private_key ] @scrub_headers = true @scrub_header_names = [] # Storage defaults @retention_days = 30 @max_buffer_size = 10_000 @buffer_ttl = 86_400 # 24 hours # Job defaults @queue_name = "findbug" @persist_batch_size = 100 @persist_interval = 30 @auto_persist = true # Web defaults @web_username = ENV["FINDBUG_USERNAME"] @web_password = ENV["FINDBUG_PASSWORD"] @web_path = "/findbug" # Alerts - initialized empty, configured via block @alerts = AlertConfiguration.new # Misc @release = ENV["FINDBUG_RELEASE"] @environment = nil # Will use Rails.env if not set @logger = nil # Will use Rails.logger if not set end |
Instance Attribute Details
#alerts ⇒ Object (readonly)
DSL for configuring alerts
Example:
config.alerts do |alerts|
alerts.email enabled: true, recipients: ["team@example.com"]
alerts.slack enabled: true, webhook_url: ENV["SLACK_WEBHOOK"]
end
152 153 154 |
# File 'lib/findbug/configuration.rb', line 152 def alerts @alerts end |
#auto_persist ⇒ Object
Whether to use the built-in background persister thread. Set to false if you want to use ActiveJob/Sidekiq instead. Default: true
133 134 135 |
# File 'lib/findbug/configuration.rb', line 133 def auto_persist @auto_persist end |
#buffer_ttl ⇒ Object
Redis key TTL for buffered events (in seconds). Events older than this are automatically expired by Redis. Default: 86400 (24 hours)
112 113 114 |
# File 'lib/findbug/configuration.rb', line 112 def buffer_ttl @buffer_ttl end |
#enabled ⇒ Object
Whether Findbug is enabled. Disable in test environments to avoid noise. Default: true (enabled)
26 27 28 |
# File 'lib/findbug/configuration.rb', line 26 def enabled @enabled end |
#environment ⇒ Object
Environment name override. Default: Rails.env
163 164 165 |
# File 'lib/findbug/configuration.rb', line 163 def environment @environment end |
#ignored_exceptions ⇒ Object
Exception classes to ignore. These won’t be captured at all. Common ignores: ActiveRecord::RecordNotFound (404s), ActionController::RoutingError Default: empty array
55 56 57 |
# File 'lib/findbug/configuration.rb', line 55 def ignored_exceptions @ignored_exceptions end |
#ignored_paths ⇒ Object
Paths to ignore (regex patterns). Useful for health checks, assets, etc. Example: [/^/health/, /^/assets/] Default: empty array
60 61 62 |
# File 'lib/findbug/configuration.rb', line 60 def ignored_paths @ignored_paths end |
#logger ⇒ Object
Custom logger. If nil, uses Rails.logger. Default: nil
167 168 169 |
# File 'lib/findbug/configuration.rb', line 167 def logger @logger end |
#max_buffer_size ⇒ Object
Maximum buffer size in Redis (number of events). Prevents Redis memory from growing unbounded if DB persistence falls behind. Default: 10000 events
107 108 109 |
# File 'lib/findbug/configuration.rb', line 107 def max_buffer_size @max_buffer_size end |
#performance_enabled ⇒ Object
Whether to enable performance monitoring (request timing, SQL queries). Default: true
66 67 68 |
# File 'lib/findbug/configuration.rb', line 66 def performance_enabled @performance_enabled end |
#performance_sample_rate ⇒ Object
Sample rate for performance monitoring (0.0 to 1.0). Performance data is more voluminous than errors, so you might want to sample. Default: 0.1 (10% of requests)
71 72 73 |
# File 'lib/findbug/configuration.rb', line 71 def performance_sample_rate @performance_sample_rate end |
#persist_batch_size ⇒ Object
Batch size for persistence job (how many events to move from Redis to DB at once). Larger = more efficient, but uses more memory. Default: 100
123 124 125 |
# File 'lib/findbug/configuration.rb', line 123 def persist_batch_size @persist_batch_size end |
#persist_interval ⇒ Object
Interval (in seconds) for the background persister thread. This is how often events are moved from Redis to the database. Default: 30 seconds
128 129 130 |
# File 'lib/findbug/configuration.rb', line 128 def persist_interval @persist_interval end |
#queue_name ⇒ Object
Queue name for Findbug’s background jobs. Default: “findbug”
118 119 120 |
# File 'lib/findbug/configuration.rb', line 118 def queue_name @queue_name end |
#redis_pool_size ⇒ Object
Size of the Redis connection pool. More connections = more concurrent writes. Rule of thumb: match your Puma/Unicorn worker count. Default: 5
36 37 38 |
# File 'lib/findbug/configuration.rb', line 36 def redis_pool_size @redis_pool_size end |
#redis_pool_timeout ⇒ Object
Timeout for getting a connection from the pool (in seconds). If all connections are busy, we wait this long before giving up. Default: 1 second (fast fail to avoid blocking your app)
41 42 43 |
# File 'lib/findbug/configuration.rb', line 41 def redis_pool_timeout @redis_pool_timeout end |
#redis_url ⇒ Object
Redis connection URL. We use a SEPARATE Redis connection from your app to avoid any interference with your caching/Sidekiq. Default: redis://localhost:6379/1 (note: database 1, not 0)
31 32 33 |
# File 'lib/findbug/configuration.rb', line 31 def redis_url @redis_url end |
#release ⇒ Object
Release/version identifier (e.g., git SHA, semantic version). Useful for tracking which deploy introduced a bug. Default: nil (auto-detected from ENV or Git)
159 160 161 |
# File 'lib/findbug/configuration.rb', line 159 def release @release end |
#retention_days ⇒ Object
How many days to keep error/performance data in the database. Older records are automatically deleted by the cleanup job. Default: 30 days
102 103 104 |
# File 'lib/findbug/configuration.rb', line 102 def retention_days @retention_days end |
#sample_rate ⇒ Object
Sample rate for error capture (0.0 to 1.0). 1.0 = capture 100% of errors 0.5 = capture 50% of errors (randomly sampled) Useful for extremely high-traffic apps where you don’t need every error. Default: 1.0 (capture everything)
50 51 52 |
# File 'lib/findbug/configuration.rb', line 50 def sample_rate @sample_rate end |
#scrub_fields ⇒ Object
Field names to scrub from captured data. These will be replaced with [FILTERED]. CRITICAL for PII/security compliance. Default: common sensitive fields
87 88 89 |
# File 'lib/findbug/configuration.rb', line 87 def scrub_fields @scrub_fields end |
#scrub_header_names ⇒ Object
Additional headers to scrub (beyond defaults). Default: empty array
95 96 97 |
# File 'lib/findbug/configuration.rb', line 95 def scrub_header_names @scrub_header_names end |
#scrub_headers ⇒ Object
Whether to scrub request headers. Default: true (scrubs Authorization, Cookie, etc.)
91 92 93 |
# File 'lib/findbug/configuration.rb', line 91 def scrub_headers @scrub_headers end |
#slow_query_threshold_ms ⇒ Object
Threshold in ms for flagging slow SQL queries. Default: 100ms
80 81 82 |
# File 'lib/findbug/configuration.rb', line 80 def slow_query_threshold_ms @slow_query_threshold_ms end |
#slow_request_threshold_ms ⇒ Object
Threshold in ms. Only record requests slower than this. Helps reduce noise from fast requests. Default: 0 (record all sampled requests)
76 77 78 |
# File 'lib/findbug/configuration.rb', line 76 def slow_request_threshold_ms @slow_request_threshold_ms end |
#web_password ⇒ Object
Password for basic auth on the dashboard. Default: nil (dashboard disabled if not set)
143 144 145 |
# File 'lib/findbug/configuration.rb', line 143 def web_password @web_password end |
#web_path ⇒ Object
Path prefix for the dashboard. The dashboard will be mounted at this path. Default: “/findbug”
147 148 149 |
# File 'lib/findbug/configuration.rb', line 147 def web_path @web_path end |
#web_username ⇒ Object
Username for basic auth on the dashboard. Default: nil (dashboard disabled if not set)
139 140 141 |
# File 'lib/findbug/configuration.rb', line 139 def web_username @web_username end |
Instance Method Details
#should_capture_exception?(exception) ⇒ Boolean
Check if we should capture this exception class
257 258 259 260 261 262 263 |
# File 'lib/findbug/configuration.rb', line 257 def should_capture_exception?(exception) return false unless enabled return false if ignored_exceptions.any? { |klass| exception.is_a?(klass) } # Apply sampling rand <= sample_rate end |
#should_capture_path?(path) ⇒ Boolean
Check if we should capture this request path
266 267 268 269 270 271 |
# File 'lib/findbug/configuration.rb', line 266 def should_capture_path?(path) return false unless enabled return false if ignored_paths.any? { |pattern| path.match?(pattern) } true end |
#should_capture_performance? ⇒ Boolean
Check if we should capture performance for this request
274 275 276 277 278 279 280 |
# File 'lib/findbug/configuration.rb', line 274 def should_capture_performance? return false unless enabled return false unless performance_enabled # Apply sampling rand <= performance_sample_rate end |
#validate! ⇒ Object
Validate configuration at startup Raises ConfigurationError if something is wrong
245 246 247 248 249 |
# File 'lib/findbug/configuration.rb', line 245 def validate! validate_sample_rates! validate_redis! validate_web_auth! end |
#web_enabled? ⇒ Boolean
Check if the dashboard should be enabled
252 253 254 |
# File 'lib/findbug/configuration.rb', line 252 def web_enabled? web_username.present? && web_password.present? end |