dead_bro 0.2.18 → 0.2.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa43ba99a6fb0fd4007b856a24ac5844236f2d0102f9ec71175c81981a91bb17
4
- data.tar.gz: c91f7fee25858bafd2edabfb162239ea8d8833405a3b4965f55e403a06dbfd05
3
+ metadata.gz: 46ac9efa7b56801c96f5f9e20f113613fa60c10337b94ee84adc59d0ea38234f
4
+ data.tar.gz: fa10f3f9436a350d8cea97caa71541ade145c88e479cd84195a2814dc43e4395
5
5
  SHA512:
6
- metadata.gz: b436b94d8d36d0b3407b09481326e443aa342c4398d4973fb517016bd3ee1f4a159a163d12a76b2294f2e4de36505b0cb568010bd8e0aecbbd0e3b4dc544069e
7
- data.tar.gz: 7981b5ea511dad34ce67c0a71afe8a09f12045a0ae778311fa42ae0426f3a689d38377528939c6f757192bd973c3d3c782f9f2124831cfac5505d4bf1ab2d177
6
+ metadata.gz: 935d4045021860632e6121b844afe1adca986297e03b0c54c0322721b6877112e1dd1e34ccda5ad1b91d52a6a5a05e829fc8c5f045ad74623d6a1b0a5e19ef66
7
+ data.tar.gz: 9171b13a16ba440015e4df1e44f260b362224c8f0ed8752f6c1a3420c97667f35ffffc97879ed2c34a829be2f95b216b552bb5b52525aa1403c988d1c3955b24
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ### Added
4
+ - Monitor thread now sends a synchronous heartbeat on startup before the first collection tick. This ensures remote settings — including `monitor_enabled` — are applied from the very first reporting cycle, so Sidekiq workers and other non-web processes that have not yet sent any metrics still receive the correct configuration immediately on boot rather than waiting up to 60 seconds for the first scheduled tick.
5
+
3
6
  ## [0.2.17] - 2026-05-25
4
7
 
5
8
  ### Added
@@ -32,18 +32,33 @@ module DeadBro
32
32
  nil
33
33
  end
34
34
 
35
- def post_heartbeat
35
+ def post_heartbeat(sync: false)
36
36
  return if @configuration.api_key.nil?
37
37
 
38
38
  @configuration.last_heartbeat_attempt_at = Time.now.utc
39
- body = {event: "heartbeat", payload: {}, sent_at: Time.now.utc.iso8601, revision: @configuration.resolve_deploy_id, gem_version: DeadBro::VERSION}
40
-
41
- dispatch_request(
42
- url: metrics_endpoint_url,
43
- body: body,
44
- event_name: "heartbeat",
45
- apply_settings: true
46
- )
39
+ body = {event: "heartbeat", payload: {rails_env: DeadBro.env}, sent_at: Time.now.utc.iso8601, revision: @configuration.resolve_deploy_id, gem_version: DeadBro::VERSION}
40
+
41
+ if sync
42
+ # Called from the monitor thread on startup — run inline so settings are
43
+ # applied before the first collection tick.
44
+ uri = URI.parse(metrics_endpoint_url)
45
+ http = Net::HTTP.new(uri.host, uri.port)
46
+ http.use_ssl = (uri.scheme == "https")
47
+ http.open_timeout = @configuration.open_timeout
48
+ http.read_timeout = @configuration.read_timeout
49
+ request = Net::HTTP::Post.new(uri.request_uri)
50
+ request["Content-Type"] = "application/json"
51
+ request["Authorization"] = "Bearer #{@configuration.api_key}"
52
+ request.body = JSON.dump(body)
53
+ perform_request(http, request, event_name: "heartbeat", apply_settings: true)
54
+ else
55
+ dispatch_request(
56
+ url: metrics_endpoint_url,
57
+ body: body,
58
+ event_name: "heartbeat",
59
+ apply_settings: true
60
+ )
61
+ end
47
62
 
48
63
  nil
49
64
  end
@@ -52,7 +67,7 @@ module DeadBro
52
67
  return if @configuration.api_key.nil?
53
68
  return unless @configuration.enabled
54
69
  return if @configuration.skip_tracking?
55
- return unless @configuration.job_queue_monitoring_enabled
70
+ return unless @configuration.monitor_enabled
56
71
  return if circuit_open?
57
72
 
58
73
  body = {payload: payload, sent_at: Time.now.utc.iso8601, revision: @configuration.resolve_deploy_id, gem_version: DeadBro::VERSION}
@@ -206,12 +221,5 @@ module DeadBro
206
221
  )
207
222
  end
208
223
 
209
- def log_debug(message)
210
- if defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger
211
- Rails.logger.debug(message)
212
- else
213
- $stdout.puts(message)
214
- end
215
- end
216
224
  end
217
225
  end
@@ -18,6 +18,7 @@ module DeadBro
18
18
  now = Time.now.utc
19
19
 
20
20
  {
21
+ kind: DeadBro.process_kind,
21
22
  pid: Process.pid,
22
23
  hostname: safe_hostname,
23
24
  boot_time: rails_boot_time,
@@ -12,7 +12,7 @@ module DeadBro
12
12
  # Remote-managed settings (overwritten by backend JSON `settings` on successful API responses)
13
13
  attr_accessor :memory_tracking_enabled, :allocation_tracking_enabled,
14
14
  :sample_rate, :slow_query_threshold_ms, :explain_analyze_enabled,
15
- :job_queue_monitoring_enabled, :enable_db_stats, :enable_process_stats, :enable_system_stats,
15
+ :monitor_enabled, :enable_db_stats, :enable_process_stats, :enable_system_stats,
16
16
  :max_sql_queries_to_send, :max_logs_to_send
17
17
 
18
18
  # Readers for exclusion lists. Writers are defined below so we can compile
@@ -58,7 +58,7 @@ module DeadBro
58
58
  enabled sample_rate memory_tracking_enabled allocation_tracking_enabled
59
59
  explain_analyze_enabled slow_query_threshold_ms max_sql_queries_to_send max_logs_to_send
60
60
  excluded_controllers excluded_jobs exclusive_controllers exclusive_jobs
61
- job_queue_monitoring_enabled enable_db_stats enable_process_stats enable_system_stats
61
+ monitor_enabled enable_db_stats enable_process_stats enable_system_stats
62
62
  ].freeze
63
63
 
64
64
  def initialize
@@ -87,7 +87,7 @@ module DeadBro
87
87
  self.excluded_jobs = []
88
88
  self.exclusive_controllers = []
89
89
  self.exclusive_jobs = []
90
- @job_queue_monitoring_enabled = false
90
+ @monitor_enabled = false
91
91
  @enable_db_stats = false
92
92
  @enable_process_stats = false
93
93
  @enable_system_stats = false
@@ -145,7 +145,7 @@ module DeadBro
145
145
  when "sample_rate", "slow_query_threshold_ms", "max_sql_queries_to_send", "max_logs_to_send"
146
146
  send(:"#{k}=", value.to_i)
147
147
  when "enabled", "memory_tracking_enabled", "allocation_tracking_enabled", "explain_analyze_enabled",
148
- "job_queue_monitoring_enabled", "enable_db_stats", "enable_process_stats", "enable_system_stats"
148
+ "monitor_enabled", "enable_db_stats", "enable_process_stats", "enable_system_stats"
149
149
  send(:"#{k}=", !!value)
150
150
  when "excluded_controllers", "excluded_jobs", "exclusive_controllers", "exclusive_jobs"
151
151
  send(:"#{k}=", Array(value).map(&:to_s))
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "digest"
3
4
  require "rack"
4
5
 
5
6
  module DeadBro
@@ -35,6 +36,8 @@ module DeadBro
35
36
  exception_class: exception.class.name,
36
37
  message: truncate(exception.message.to_s, 1000),
37
38
  backtrace: safe_backtrace(exception),
39
+ fingerprint: compute_fingerprint(exception),
40
+ cause_chain: build_cause_chain(exception),
38
41
  occurred_at: Time.now.utc.to_i,
39
42
  rack:
40
43
  {
@@ -51,6 +54,7 @@ module DeadBro
51
54
  rails_env: DeadBro.env,
52
55
  app: safe_app_name,
53
56
  pid: Process.pid,
57
+ process_kind: DeadBro.process_kind,
54
58
  logs: DeadBro.logger.logs
55
59
  }
56
60
  end
@@ -67,6 +71,42 @@ module DeadBro
67
71
  []
68
72
  end
69
73
 
74
+ def normalize_message(msg)
75
+ msg.to_s
76
+ .gsub(/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/i, "UUID")
77
+ .gsub(/\b\d+\b/, "N")
78
+ .gsub(/"[^"]*"/, '"?"')
79
+ .gsub(/'[^']*'/, "'?'")
80
+ .strip
81
+ end
82
+
83
+ def compute_fingerprint(exception)
84
+ top_frame = Array(exception.backtrace).first.to_s.gsub(/:\d+:in /, ":N:in ")
85
+ input = "#{exception.class.name}|#{normalize_message(exception.message)}|#{top_frame}"
86
+ Digest::SHA256.hexdigest(input)[0, 16]
87
+ rescue
88
+ nil
89
+ end
90
+
91
+ def build_cause_chain(exception)
92
+ return [] unless exception
93
+ chain = []
94
+ cause = exception.cause
95
+ depth = 0
96
+ while cause && depth < 5
97
+ chain << {
98
+ exception_class: cause.class.name,
99
+ message: truncate(cause.message.to_s, 500),
100
+ backtrace_top: Array(cause.backtrace).first(3)
101
+ }
102
+ cause = cause.cause
103
+ depth += 1
104
+ end
105
+ chain
106
+ rescue
107
+ []
108
+ end
109
+
70
110
  def safe_params(req)
71
111
  return {} unless req
72
112
 
@@ -115,6 +115,7 @@ module DeadBro
115
115
  sql_queries: sql_queries,
116
116
  rails_env: DeadBro.env,
117
117
  host: safe_host,
118
+ process_kind: DeadBro.process_kind,
118
119
  memory_usage: memory_usage_mb,
119
120
  gc_stats: gc_stats,
120
121
  memory_events: memory_events,
@@ -213,6 +214,7 @@ module DeadBro
213
214
  backtrace: Array(exception&.backtrace).first(50),
214
215
  rails_env: DeadBro.env,
215
216
  host: safe_host,
217
+ process_kind: DeadBro.process_kind,
216
218
  memory_usage: memory_usage_mb,
217
219
  gc_stats: gc_stats,
218
220
  memory_events: memory_events,
@@ -24,6 +24,16 @@ module DeadBro
24
24
  @running = true
25
25
  @thread = Thread.new do
26
26
  Thread.current.abort_on_exception = false
27
+
28
+ # Fetch initial settings before the first collection tick so processes
29
+ # that haven't yet posted any metrics (e.g. Sidekiq at boot) still get
30
+ # monitor_enabled and other remote settings from the backend.
31
+ begin
32
+ @client.post_heartbeat(sync: true)
33
+ rescue => e
34
+ log_error("Error fetching initial settings: #{e.message}")
35
+ end
36
+
27
37
  loop do
28
38
  break unless @running
29
39
 
@@ -59,6 +69,7 @@ module DeadBro
59
69
  environment: DeadBro.env,
60
70
  host: process_hostname,
61
71
  pid: Process.pid,
72
+ process_kind: DeadBro.process_kind,
62
73
  current_time: Time.now.utc.iso8601,
63
74
  jobs: DeadBro::Collectors::Jobs.collect,
64
75
  network: DeadBro::Collectors::Network.collect
@@ -86,10 +97,11 @@ module DeadBro
86
97
  end
87
98
 
88
99
  def log_error(message)
100
+ msg = "[DeadBro::Monitor] #{message}"
89
101
  if defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger
90
- Rails.logger.error("[DeadBro::Monitor] #{message}")
102
+ Rails.logger.error(msg)
91
103
  else
92
- $stderr.puts("[DeadBro::Monitor] #{message}")
104
+ warn(msg)
93
105
  end
94
106
  end
95
107
 
@@ -68,7 +68,7 @@ if defined?(Rails) && defined?(Rails::Railtie)
68
68
  end
69
69
 
70
70
  # Always start the monitor thread. The thread runs every 60s but
71
- # post_monitor_stats skips the HTTP POST when job_queue_monitoring_enabled
71
+ # post_monitor_stats skips the HTTP POST when monitor_enabled
72
72
  # is false, so the backend can toggle monitoring on/off mid-process.
73
73
  require "dead_bro/monitor"
74
74
  DeadBro.monitor = DeadBro::Monitor.new(client: shared_client)
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "digest"
3
4
  require "active_support/notifications"
4
5
 
5
6
  module DeadBro
@@ -133,12 +134,15 @@ module DeadBro
133
134
  duration_ms: duration_ms,
134
135
  rails_env: DeadBro.env,
135
136
  host: safe_host,
137
+ process_kind: DeadBro.process_kind,
136
138
  params: safe_params(data),
137
139
  user_agent: safe_user_agent(data),
138
140
  user_id: extract_user_id(data),
139
141
  exception_class: exception_class || exception_obj&.class&.name,
140
142
  message: (exception_message || exception_obj&.message).to_s[0, 1000],
141
143
  backtrace: backtrace,
144
+ fingerprint: compute_error_fingerprint(exception_obj),
145
+ cause_chain: build_cause_chain(exception_obj),
142
146
  error: true,
143
147
  logs: DeadBro.logger.logs
144
148
  }
@@ -163,6 +167,7 @@ module DeadBro
163
167
  db_runtime_ms: data[:db_runtime],
164
168
  host: safe_host,
165
169
  rails_env: DeadBro.env,
170
+ process_kind: DeadBro.process_kind,
166
171
  params: safe_params(data),
167
172
  user_agent: safe_user_agent(data),
168
173
  user_id: extract_user_id(data),
@@ -401,5 +406,42 @@ module DeadBro
401
406
  rescue
402
407
  nil
403
408
  end
409
+
410
+ def self.normalize_error_message(msg)
411
+ msg.to_s
412
+ .gsub(/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/i, "UUID")
413
+ .gsub(/\b\d+\b/, "N")
414
+ .gsub(/"[^"]*"/, '"?"')
415
+ .gsub(/'[^']*'/, "'?'")
416
+ .strip
417
+ end
418
+
419
+ def self.compute_error_fingerprint(exception)
420
+ return nil unless exception
421
+ top_frame = Array(exception.backtrace).first.to_s.gsub(/:\d+:in /, ":N:in ")
422
+ input = "#{exception.class.name}|#{normalize_error_message(exception.message)}|#{top_frame}"
423
+ Digest::SHA256.hexdigest(input)[0, 16]
424
+ rescue
425
+ nil
426
+ end
427
+
428
+ def self.build_cause_chain(exception)
429
+ return [] unless exception
430
+ chain = []
431
+ cause = exception.cause
432
+ depth = 0
433
+ while cause && depth < 5
434
+ chain << {
435
+ exception_class: cause.class.name,
436
+ message: cause.message.to_s[0, 500],
437
+ backtrace_top: Array(cause.backtrace).first(3)
438
+ }
439
+ cause = cause.cause
440
+ depth += 1
441
+ end
442
+ chain
443
+ rescue
444
+ []
445
+ end
404
446
  end
405
447
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeadBro
4
- VERSION = "0.2.18"
4
+ VERSION = "0.2.20"
5
5
  end
data/lib/dead_bro.rb CHANGED
@@ -127,6 +127,30 @@ module DeadBro
127
127
  "development"
128
128
  end
129
129
 
130
+ def self.process_kind
131
+ @process_kind ||= begin
132
+ fingerprint = "#{$PROGRAM_NAME} #{process_command_line}".downcase
133
+ case
134
+ when fingerprint.match?(/sidekiq|good_job|solid_queue|delayed_job/) then "worker"
135
+ when fingerprint.match?(/puma|passenger|unicorn|falcon/) then "web"
136
+ when fingerprint.include?("console") then "console"
137
+ when fingerprint.include?("rake") then "task"
138
+ else "app"
139
+ end
140
+ end
141
+ rescue
142
+ "app"
143
+ end
144
+
145
+ def self.process_command_line
146
+ # /proc/self/cmdline is Linux-only; on macOS/Windows the fallback to
147
+ # $PROGRAM_NAME is used, which may miss some process fingerprints (e.g.
148
+ # a Sidekiq invocation that uses a wrapper script).
149
+ File.readable?("/proc/self/cmdline") ? File.read("/proc/self/cmdline").tr("\0", " ").strip : $PROGRAM_NAME.to_s
150
+ rescue
151
+ $PROGRAM_NAME.to_s
152
+ end
153
+
130
154
  # Returns the monitor instance
131
155
  def self.monitor
132
156
  @monitor
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dead_bro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.18
4
+ version: 0.2.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emanuel Comsa
@@ -18,7 +18,6 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - CHANGELOG.md
21
- - FEATURES.md
22
21
  - README.md
23
22
  - lib/dead_bro.rb
24
23
  - lib/dead_bro/ar_object_tracker.rb
@@ -75,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
74
  - !ruby/object:Gem::Version
76
75
  version: '0'
77
76
  requirements: []
78
- rubygems_version: 4.0.9
77
+ rubygems_version: 4.0.10
79
78
  specification_version: 4
80
79
  summary: Minimal APM for Rails apps.
81
80
  test_files: []
data/FEATURES.md DELETED
@@ -1,333 +0,0 @@
1
- # ApmBro Feature List
2
-
3
- A comprehensive feature list for comparing ApmBro with other APM (Application Performance Monitoring) tools.
4
-
5
- ## Core Architecture
6
-
7
- - **Rails Integration**: Automatic subscription to Rails events via ActiveSupport::Notifications
8
- - **Zero-Configuration Setup**: Works out of the box with minimal configuration
9
- - **Asynchronous Metrics Posting**: Non-blocking HTTP requests using background threads
10
- - **Thread-Local Storage**: Per-request metric collection using thread-local variables
11
- - **Circuit Breaker Pattern**: Built-in circuit breaker to prevent cascading failures when APM endpoint is down
12
- - **Deploy Tracking**: Automatic deploy ID resolution from multiple sources (Rails settings, ENV vars, Heroku, Git)
13
-
14
- ## Request Tracking
15
-
16
- ### Controller Action Monitoring
17
- - **Automatic Tracking**: Tracks all controller actions automatically
18
- - **Request Duration**: Measures total request processing time
19
- - **HTTP Method & Path**: Captures HTTP method and request path
20
- - **Status Codes**: Tracks HTTP response status codes
21
- - **View Runtime**: Separate tracking of view rendering time
22
- - **Database Runtime**: Separate tracking of database query time
23
- - **Request Parameters**: Captures request parameters (with sensitive data filtering)
24
- - **User Agent**: Tracks user agent strings
25
- - **User ID Extraction**: Extracts authenticated user ID (supports Warden)
26
- - **Environment Context**: Tracks Rails environment (development, staging, production)
27
-
28
- ### Request Sampling
29
- - **Configurable Sample Rate**: Percentage-based sampling (1-100%)
30
- - **Random Sampling**: Each request has random chance of being tracked
31
- - **Consistent Per-Request**: Sampling decision applies to all metrics for a request
32
- - **Error Override**: Errors are always tracked regardless of sampling
33
- - **Cost Optimization**: Reduces data volume and costs for high-traffic applications
34
-
35
- ### Exclusion Rules
36
- - **Controller Exclusion**: Exclude entire controllers from tracking
37
- - **Action Exclusion**: Exclude specific controller#action combinations
38
- - **Wildcard Support**: Pattern matching with `*` wildcards (e.g., `Admin::*`, `Admin::*#*`)
39
- - **Job Exclusion**: Exclude specific background jobs from tracking
40
- - **Flexible Configuration**: Configure via initializer, Rails settings, or environment variables
41
-
42
- ## SQL Query Tracking
43
-
44
- ### Query Details
45
- - **Full SQL Tracking**: Captures all SQL queries executed during requests and jobs
46
- - **Query Sanitization**: Automatically sanitizes SQL to remove sensitive data
47
- - **Query Name**: Tracks query names (e.g., "User Load", "User Update")
48
- - **Duration Measurement**: Precise query execution time in milliseconds
49
- - **Cache Detection**: Identifies cached queries
50
- - **Connection ID**: Tracks database connection ID
51
- - **Call Stack Traces**: Full backtrace showing where queries were executed
52
- - **Object Allocations**: Optional tracking of object allocations per query
53
-
54
- ### Query Performance Analysis
55
- - **Slow Query Detection**: Configurable threshold for identifying slow queries
56
- - **EXPLAIN ANALYZE**: Automatic execution plan capture for slow queries
57
- - **Background Execution**: EXPLAIN ANALYZE runs in separate thread (non-blocking)
58
- - **Multi-Database Support**: Works with PostgreSQL, MySQL, SQLite, and others
59
- - **Smart Filtering**: Automatically skips transaction queries (BEGIN, COMMIT, ROLLBACK)
60
- - **Execution Plan Details**:
61
- - PostgreSQL: Full EXPLAIN ANALYZE with buffer usage statistics
62
- - MySQL: EXPLAIN ANALYZE with actual execution times
63
- - SQLite: EXPLAIN QUERY PLAN output
64
- - **Query Optimization Insights**: Helps identify missing indexes, full table scans, JOIN issues
65
-
66
- ## View Rendering Tracking
67
-
68
- ### View Performance
69
- - **Template Rendering**: Tracks main template rendering
70
- - **Partial Rendering**: Tracks partial template rendering with cache key information
71
- - **Collection Rendering**: Tracks collection rendering (partials in loops)
72
- - **Rendering Duration**: Precise timing for each view component
73
- - **Virtual Path Tracking**: Tracks view virtual paths
74
- - **Layout Information**: Captures layout usage
75
-
76
- ### View Analysis
77
- - **Slow View Detection**: Identifies the slowest rendering views
78
- - **Frequency Analysis**: Tracks most frequently rendered views
79
- - **Cache Hit Rate**: Calculates cache hit rates for partials
80
- - **Collection Cache Analysis**: Tracks cache hit rates for collection rendering
81
- - **Performance Metrics**:
82
- - Total views rendered per request
83
- - Total view rendering duration
84
- - Average view rendering duration
85
- - Breakdown by view type (template, partial, collection)
86
-
87
- ## Memory Tracking & Leak Detection
88
-
89
- ### Lightweight Memory Tracking (Default)
90
- - **Memory Usage Monitoring**: Tracks memory consumption per request using GC stats
91
- - **Memory Growth Tracking**: Measures memory growth during request processing
92
- - **GC Statistics**: Tracks garbage collection count and heap pages
93
- - **Minimal Performance Impact**: ~0.1ms overhead per request
94
- - **Memory Before/After**: Captures memory state at request start and end
95
-
96
- ### Detailed Allocation Tracking (Optional)
97
- - **Object Allocation Tracking**: Detailed tracking of object allocations (disabled by default)
98
- - **Allocation Sampling**: Configurable sampling rate for allocations
99
- - **Large Object Detection**: Identifies objects larger than 1MB threshold
100
- - **Memory Snapshots**: Periodic memory snapshots during request processing
101
- - **Object Count Tracking**: Tracks object counts before and after requests
102
- - **Performance Impact**: ~2-5ms overhead per request (only when enabled)
103
-
104
- ### Memory Leak Detection
105
- - **Pattern Detection**: Detects growing memory patterns over time
106
- - **GC Efficiency Analysis**: Monitors garbage collection effectiveness
107
- - **Heap Page Tracking**: Tracks heap page growth
108
- - **Request Correlation**: Correlates memory growth with specific controllers/actions
109
-
110
- ## Background Job Tracking
111
-
112
- ### Job Execution Monitoring
113
- - **ActiveJob Integration**: Automatic tracking when ActiveJob is available
114
- - **Job Class Tracking**: Tracks job class names
115
- - **Job ID**: Captures unique job identifiers
116
- - **Queue Name**: Tracks which queue processed the job
117
- - **Job Arguments**: Captures job arguments (with sensitive data filtering)
118
- - **Duration Measurement**: Precise job execution time in milliseconds
119
- - **Status Tracking**: Tracks job status (completed or failed)
120
-
121
- ### Job Error Tracking
122
- - **Exception Capture**: Captures exceptions from failed jobs
123
- - **Exception Class**: Tracks exception class names
124
- - **Exception Messages**: Captures exception messages (truncated to 1000 chars)
125
- - **Backtraces**: Full exception backtraces (first 50 lines)
126
- - **SQL Query Context**: Includes SQL queries executed during failed jobs
127
- - **Memory Context**: Includes memory usage during job execution
128
-
129
- ### Job SQL Tracking
130
- - **SQL Query Tracking**: Tracks all SQL queries executed during job processing
131
- - **Query Details**: Same detailed SQL tracking as request tracking
132
- - **Query Context**: Full context of database operations in background jobs
133
-
134
- ## Cache Tracking
135
-
136
- ### Cache Operations
137
- - **Read Operations**: Tracks cache read operations
138
- - **Write Operations**: Tracks cache write operations
139
- - **Delete Operations**: Tracks cache delete operations
140
- - **Existence Checks**: Tracks cache existence checks
141
- - **Fetch Operations**: Tracks cache fetch with hit/miss detection
142
- - **Multi-Read Operations**: Tracks cache read_multi operations
143
- - **Multi-Write Operations**: Tracks cache write_multi operations
144
- - **Cache Generation**: Tracks cache generation events
145
-
146
- ### Cache Analysis
147
- - **Cache Hit Detection**: Identifies cache hits vs misses
148
- - **Cache Key Tracking**: Tracks cache keys (truncated to 200 chars)
149
- - **Store Information**: Identifies which cache store was used
150
- - **Namespace Tracking**: Tracks cache namespaces
151
- - **Duration Measurement**: Precise timing for each cache operation
152
- - **Hit Rate Calculation**: Calculates cache hit rates per request
153
-
154
- ## Redis Tracking
155
-
156
- ### Redis Command Tracking
157
- - **Command Monitoring**: Tracks all Redis commands executed
158
- - **Command Name**: Captures Redis command names (GET, SET, etc.)
159
- - **Key Tracking**: Tracks Redis keys (truncated to 200 chars)
160
- - **Argument Count**: Tracks number of arguments per command
161
- - **Database Selection**: Tracks which Redis database is used
162
- - **Duration Measurement**: Precise timing for each Redis command
163
- - **Error Tracking**: Captures Redis command errors
164
-
165
- ### Advanced Redis Features
166
- - **Pipeline Support**: Tracks Redis pipeline operations with command counts
167
- - **Multi/Transaction Support**: Tracks Redis MULTI/EXEC transactions
168
- - **ActiveSupport Integration**: Subscribes to ActiveSupport::Notifications for Redis events
169
- - **Client Instrumentation**: Direct instrumentation of Redis::Client for comprehensive coverage
170
-
171
- ## Error Tracking
172
-
173
- ### Exception Handling
174
- - **Automatic Exception Capture**: Captures exceptions from controller actions
175
- - **Exception Class**: Tracks exception class names
176
- - **Exception Messages**: Captures exception messages (truncated to 1000 chars)
177
- - **Full Backtraces**: Captures complete exception backtraces (first 50 lines)
178
- - **Request Context**: Includes full request context with exceptions
179
- - **Error Flagging**: Errors are marked and always tracked (even with sampling)
180
-
181
- ### Error Context
182
- - **Controller/Action**: Identifies where the error occurred
183
- - **Request Parameters**: Includes request parameters at time of error
184
- - **User Information**: Includes user ID if available
185
- - **SQL Queries**: Includes SQL queries executed before error
186
- - **Memory State**: Includes memory usage at time of error
187
- - **Log Messages**: Includes application logs captured during request
188
-
189
- ## HTTP Instrumentation
190
-
191
- ### Outgoing HTTP Tracking
192
- - **HTTP Request Tracking**: Tracks outgoing HTTP requests (via middleware)
193
- - **Request Context**: Captures HTTP request details
194
- - **Response Context**: Captures HTTP response details
195
- - **Duration Measurement**: Tracks HTTP request duration
196
-
197
- ## Configuration & Flexibility
198
-
199
- ### Configuration Options
200
- - **API Key Management**: Multiple sources (config, Rails credentials, ENV)
201
- - **Endpoint Configuration**: Configurable endpoint URL
202
- - **Timeout Settings**: Configurable open and read timeouts
203
- - **Enable/Disable Toggle**: Can be enabled/disabled via configuration
204
- - **Environment Detection**: Automatic Rails environment detection
205
-
206
- ### Circuit Breaker Configuration
207
- - **Failure Threshold**: Configurable failure threshold (default: 3)
208
- - **Recovery Timeout**: Configurable recovery timeout (default: 60 seconds)
209
- - **Retry Timeout**: Configurable retry timeout (default: 300 seconds)
210
- - **Enable/Disable**: Can enable/disable circuit breaker
211
-
212
- ### Memory Tracking Configuration
213
- - **Memory Tracking Toggle**: Enable/disable memory tracking
214
- - **Allocation Tracking Toggle**: Enable/disable detailed allocation tracking
215
- - **Sampling Configuration**: Configurable request sampling rate
216
-
217
- ### Query Analysis Configuration
218
- - **Slow Query Threshold**: Configurable threshold in milliseconds (default: 500ms)
219
- - **EXPLAIN ANALYZE Toggle**: Enable/disable automatic EXPLAIN ANALYZE
220
-
221
- ## Data Safety & Privacy
222
-
223
- ### Data Sanitization
224
- - **SQL Sanitization**: Automatically sanitizes SQL queries
225
- - **Parameter Filtering**: Filters sensitive parameters (password, token, secret, key)
226
- - **Argument Truncation**: Limits and truncates job arguments
227
- - **Key Truncation**: Truncates cache and Redis keys to 200 characters
228
- - **Value Truncation**: Recursively truncates nested values to prevent huge payloads
229
- - **String Limits**: Limits string values (e.g., user agent to 200 chars, messages to 1000 chars)
230
-
231
- ### Data Limits
232
- - **Array Limits**: Limits array sizes (e.g., first 10 job arguments, first 5 array elements)
233
- - **Hash Limits**: Limits hash key counts (e.g., first 20 hash keys, first 30 params)
234
- - **Backtrace Limits**: Limits backtraces to first 50 lines
235
- - **Allocation Limits**: Limits allocations tracked per request (max 1000)
236
-
237
- ## Performance & Reliability
238
-
239
- ### Performance Optimizations
240
- - **Asynchronous Posting**: Non-blocking HTTP requests
241
- - **Lightweight Default Mode**: Minimal overhead in default configuration
242
- - **Sampling Support**: Reduces data volume for high-traffic applications
243
- - **Thread-Local Storage**: Efficient per-request data collection
244
- - **Background EXPLAIN**: EXPLAIN ANALYZE runs in background thread
245
-
246
- ### Reliability Features
247
- - **Circuit Breaker**: Prevents cascading failures
248
- - **Error Handling**: Comprehensive error handling to prevent instrumentation failures
249
- - **Graceful Degradation**: Continues working even if some features fail
250
- - **Timeout Protection**: Configurable timeouts prevent hanging requests
251
-
252
- ## Integration & Compatibility
253
-
254
- ### Framework Support
255
- - **Rails Integration**: Full Rails integration via Railtie
256
- - **ActiveSupport Notifications**: Uses ActiveSupport::Notifications for event subscription
257
- - **ActiveRecord Integration**: Tracks ActiveRecord SQL queries
258
- - **ActiveJob Integration**: Tracks ActiveJob background jobs
259
- - **ActionView Integration**: Tracks ActionView rendering
260
-
261
- ### Database Support
262
- - **PostgreSQL**: Full support with EXPLAIN ANALYZE
263
- - **MySQL**: Full support with EXPLAIN ANALYZE
264
- - **SQLite**: Full support with EXPLAIN QUERY PLAN
265
- - **Other Databases**: Basic support with standard EXPLAIN
266
-
267
- ### Cache Store Support
268
- - **All Cache Stores**: Works with any Rails cache store
269
- - **Multi-Store Support**: Tracks cache operations across different stores
270
-
271
- ### Redis Support
272
- - **Redis Gem**: Works with redis gem
273
- - **Client Instrumentation**: Direct instrumentation of Redis::Client
274
- - **Pipeline Support**: Tracks Redis pipelines
275
- - **Transaction Support**: Tracks Redis MULTI/EXEC transactions
276
-
277
- ## Logging & Debugging
278
-
279
- ### Application Logging
280
- - **Log Capture**: Captures application logs during request processing
281
- - **Log Context**: Includes logs in metric payloads
282
- - **Debug Logging**: Optional debug logging for skipped requests
283
-
284
- ## Deployment & Environment
285
-
286
- ### Deploy Tracking
287
- - **Deploy ID Resolution**: Multiple sources for deploy identification (`Configuration#deploy_id=` wins when set, then ENV in `Configuration::DEPLOY_REVISION_ENV_KEYS` order—including `DEAD_BRO_DEPLOY_ID`, git/CI vars, `DD_VERSION`, etc.), otherwise a **per-process UUID** (fine for single dyno/process; unusable alone for fleets like ECS replicas)
288
- - **Revision Tracking**: Includes deploy/revision ID in all metric payloads
289
-
290
- ### Environment Support
291
- - **Rails Environment**: Automatic Rails environment detection
292
- - **Rack Environment**: Fallback to RACK_ENV or RAILS_ENV
293
- - **Environment Context**: Includes environment in all metric payloads
294
-
295
- ## Data Collection & Transmission
296
-
297
- ### Metric Payload Structure
298
- - **Structured Data**: Well-structured JSON payloads
299
- - **Event Names**: Descriptive event names for different metric types
300
- - **Timestamp Tracking**: ISO8601 timestamps for all metrics
301
- - **Metadata**: Rich metadata including environment, host, deploy ID
302
-
303
- ### HTTP Client
304
- - **HTTPS Support**: Secure HTTPS communication
305
- - **Bearer Token Auth**: API key authentication via Bearer tokens
306
- - **JSON Encoding**: JSON-encoded payloads
307
- - **Custom Headers**: Proper Content-Type and Authorization headers
308
-
309
- ## Comparison-Ready Features
310
-
311
- ### Unique Differentiators
312
- 1. **Automatic EXPLAIN ANALYZE**: Background execution plan capture for slow queries
313
- 2. **Lightweight Memory Tracking**: Low-overhead memory monitoring by default
314
- 3. **Comprehensive Cache Tracking**: Detailed cache operation tracking
315
- 4. **Redis Instrumentation**: Full Redis command tracking including pipelines
316
- 5. **View Rendering Analysis**: Detailed view performance analysis with cache hit rates
317
- 6. **Flexible Exclusion Rules**: Wildcard support for controller/job exclusion
318
- 7. **Request Sampling**: Configurable percentage-based sampling
319
- 8. **Circuit Breaker**: Built-in resilience for APM endpoint failures
320
- 9. **Multi-Source Configuration**: Flexible configuration from multiple sources
321
- 10. **Deploy Tracking**: Automatic deploy ID resolution from multiple sources
322
-
323
- ### Standard APM Features
324
- - Request/response tracking
325
- - SQL query tracking
326
- - Error tracking
327
- - Background job tracking
328
- - Memory tracking
329
- - Performance metrics
330
- - Exception handling
331
- - User context
332
- - Environment tracking
333
-