apm_bro 0.1.13 → 0.1.15

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.
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/notifications"
4
- require "thread"
3
+ begin
4
+ require "active_support/notifications"
5
+ rescue LoadError
6
+ # ActiveSupport not available
7
+ end
5
8
 
6
9
  module ApmBro
7
10
  class SqlSubscriber
8
- SQL_EVENT_NAME = "sql.active_record".freeze
11
+ SQL_EVENT_NAME = "sql.active_record"
9
12
  THREAD_LOCAL_KEY = :apm_bro_sql_queries
10
13
  THREAD_LOCAL_ALLOC_START_KEY = :apm_bro_sql_alloc_start
11
14
  THREAD_LOCAL_ALLOC_RESULTS_KEY = :apm_bro_sql_alloc_results
@@ -16,7 +19,7 @@ module ApmBro
16
19
  if ActiveSupport::Notifications.notifier.respond_to?(:subscribe)
17
20
  begin
18
21
  ActiveSupport::Notifications.notifier.subscribe(SQL_EVENT_NAME, SqlAllocListener.new)
19
- rescue StandardError
22
+ rescue
20
23
  end
21
24
  end
22
25
 
@@ -30,11 +33,11 @@ module ApmBro
30
33
  begin
31
34
  alloc_results = Thread.current[THREAD_LOCAL_ALLOC_RESULTS_KEY]
32
35
  allocations = alloc_results && alloc_results.delete(unique_id)
33
-
36
+
34
37
  # Get the captured backtrace from when the query started
35
38
  backtrace_map = Thread.current[THREAD_LOCAL_BACKTRACE_KEY]
36
39
  captured_backtrace = backtrace_map && backtrace_map.delete(unique_id)
37
- rescue StandardError
40
+ rescue
38
41
  end
39
42
 
40
43
  query_info = {
@@ -48,7 +51,6 @@ module ApmBro
48
51
  }
49
52
  # Add to thread-local storage
50
53
  Thread.current[THREAD_LOCAL_KEY] << query_info
51
-
52
54
  end
53
55
  end
54
56
 
@@ -74,14 +76,14 @@ module ApmBro
74
76
  # Remove sensitive data patterns
75
77
  sql = sql.gsub(/\b(password|token|secret|key|ssn|credit_card)\s*=\s*['"][^'"]*['"]/i, '\1 = ?')
76
78
  sql = sql.gsub(/\b(password|token|secret|key|ssn|credit_card)\s*=\s*[^'",\s)]+/i, '\1 = ?')
77
-
79
+
78
80
  # Remove specific values in WHERE clauses that might be sensitive
79
81
  sql = sql.gsub(/WHERE\s+[^=]+=\s*['"][^'"]*['"]/i) do |match|
80
- match.gsub(/=\s*['"][^'"]*['"]/, '= ?')
82
+ match.gsub(/=\s*['"][^'"]*['"]/, "= ?")
81
83
  end
82
84
 
83
85
  # Limit query length to prevent huge payloads
84
- sql.length > 1000 ? sql[0..1000] + "..." : sql
86
+ (sql.length > 1000) ? sql[0..1000] + "..." : sql
85
87
  end
86
88
 
87
89
  def self.safe_query_trace(data, captured_backtrace = nil)
@@ -89,94 +91,93 @@ module ApmBro
89
91
 
90
92
  # Build trace from available data fields
91
93
  trace = []
92
-
94
+
93
95
  # Use filename, line, and method if available
94
96
  if data[:filename] && data[:line] && data[:method]
95
97
  trace << "#{data[:filename]}:#{data[:line]}:in `#{data[:method]}'"
96
98
  end
97
-
99
+
98
100
  # Use the captured backtrace from when the query started (most accurate)
99
101
  if captured_backtrace && captured_backtrace.is_a?(Array) && !captured_backtrace.empty?
100
102
  # Filter to only include frames that contain "app/" (application code)
101
103
  app_frames = captured_backtrace.select do |frame|
102
- frame.include?('/app/')
104
+ frame.include?("app/") && !frame.include?("/vendor/")
103
105
  end
104
-
106
+
105
107
  caller_trace = app_frames.map do |line|
106
108
  # Remove any potential sensitive information from file paths
107
- line.gsub(/\/[^\/]*(password|secret|key|token)[^\/]*\//i, '/[FILTERED]/')
109
+ line.gsub(/\/[^\/]*(password|secret|key|token)[^\/]*\//i, "/[FILTERED]/")
108
110
  end
109
-
111
+
110
112
  trace.concat(caller_trace)
111
113
  else
112
114
  # Fallback: try to get backtrace from current context
113
115
  begin
114
116
  # Get all available frames - we'll filter to find application code
115
117
  all_frames = Thread.current.backtrace || []
116
-
118
+
117
119
  if all_frames.empty?
118
120
  # Fallback to caller_locations if backtrace is empty
119
121
  locations = caller_locations(1, 50)
120
122
  all_frames = locations.map { |loc| "#{loc.path}:#{loc.lineno}:in `#{loc.label}'" } if locations
121
123
  end
122
-
124
+
123
125
  # Filter to only include frames that contain "app/" (application code)
124
126
  app_frames = all_frames.select do |frame|
125
- frame.include?('/app/')
127
+ frame.include?("app/") && !frame.include?("/vendor/")
126
128
  end
127
-
129
+
128
130
  caller_trace = app_frames.map do |line|
129
- line.gsub(/\/[^\/]*(password|secret|key|token)[^\/]*\//i, '/[FILTERED]/')
131
+ line.gsub(/\/[^\/]*(password|secret|key|token)[^\/]*\//i, "/[FILTERED]/")
130
132
  end
131
-
133
+
132
134
  trace.concat(caller_trace)
133
- rescue StandardError
135
+ rescue
134
136
  # If backtrace fails, try caller as fallback
135
137
  begin
136
138
  caller_stack = caller(20, 50) # Get more frames to find app/ frames
137
- app_frames = caller_stack.select { |frame| frame.include?('/app/') }
139
+ app_frames = caller_stack.select { |frame| frame.include?("app/") && !frame.include?("/vendor/") }
138
140
  caller_trace = app_frames.map do |line|
139
- line.gsub(/\/[^\/]*(password|secret|key|token)[^\/]*\//i, '/[FILTERED]/')
141
+ line.gsub(/\/[^\/]*(password|secret|key|token)[^\/]*\//i, "/[FILTERED]/")
140
142
  end
141
143
  trace.concat(caller_trace)
142
- rescue StandardError
144
+ rescue
143
145
  # If caller also fails, we still have the immediate location
144
146
  end
145
147
  end
146
148
  end
147
-
149
+
148
150
  # If we have a backtrace in the data, use it (but it's usually nil for SQL events)
149
151
  if data[:backtrace] && data[:backtrace].is_a?(Array)
150
152
  # Filter to only include frames that contain "app/"
151
153
  app_backtrace = data[:backtrace].select do |line|
152
- line.is_a?(String) && line.include?('/app/')
154
+ line.is_a?(String) && line.include?("app/") && !line.include?("/vendor/")
153
155
  end
154
-
156
+
155
157
  backtrace_trace = app_backtrace.map do |line|
156
158
  case line
157
159
  when String
158
- line.gsub(/\/[^\/]*(password|secret|key|token)[^\/]*\//i, '/[FILTERED]/')
160
+ line.gsub(/\/[^\/]*(password|secret|key|token)[^\/]*\//i, "/[FILTERED]/")
159
161
  else
160
162
  line.to_s
161
163
  end
162
164
  end
163
165
  trace.concat(backtrace_trace)
164
166
  end
165
-
167
+
166
168
  # Remove duplicates and return all app/ frames (no limit)
167
169
  trace.uniq.map do |line|
168
170
  case line
169
171
  when String
170
172
  # Remove any potential sensitive information from file paths
171
- line.gsub(/\/[^\/]*(password|secret|key|token)[^\/]*\//i, '/[FILTERED]/')
173
+ line.gsub(/\/[^\/]*(password|secret|key|token)[^\/]*\//i, "/[FILTERED]/")
172
174
  else
173
175
  line.to_s
174
176
  end
175
177
  end
176
- rescue StandardError
178
+ rescue
177
179
  []
178
180
  end
179
-
180
181
  end
181
182
  end
182
183
 
@@ -184,36 +185,36 @@ module ApmBro
184
185
  # Listener that records GC allocation deltas per SQL event id
185
186
  class SqlAllocListener
186
187
  def start(name, id, payload)
187
- begin
188
- map = (Thread.current[ApmBro::SqlSubscriber::THREAD_LOCAL_ALLOC_START_KEY] ||= {})
189
- map[id] = GC.stat[:total_allocated_objects] if defined?(GC) && GC.respond_to?(:stat)
190
-
191
- # Capture the backtrace at query start time (before notification system processes it)
192
- # This gives us the actual call stack where the SQL was executed
193
- backtrace_map = (Thread.current[ApmBro::SqlSubscriber::THREAD_LOCAL_BACKTRACE_KEY] ||= {})
194
- captured_backtrace = Thread.current.backtrace
195
- if captured_backtrace && captured_backtrace.is_a?(Array)
196
- # Skip the first few frames (our listener code) to get to the actual query execution
197
- backtrace_map[id] = captured_backtrace[5..-1] || captured_backtrace
198
- end
199
- rescue StandardError
188
+ map = (Thread.current[ApmBro::SqlSubscriber::THREAD_LOCAL_ALLOC_START_KEY] ||= {})
189
+ map[id] = GC.stat[:total_allocated_objects] if defined?(GC) && GC.respond_to?(:stat)
190
+
191
+ # Capture the backtrace at query start time (before notification system processes it)
192
+ # This gives us the actual call stack where the SQL was executed
193
+ backtrace_map = (Thread.current[ApmBro::SqlSubscriber::THREAD_LOCAL_BACKTRACE_KEY] ||= {})
194
+ captured_backtrace = Thread.current.backtrace
195
+ if captured_backtrace && captured_backtrace.is_a?(Array)
196
+ # Skip the first few frames (our listener code) to get to the actual query execution
197
+ backtrace_map[id] = captured_backtrace[5..-1] || captured_backtrace
200
198
  end
199
+ rescue
201
200
  end
202
201
 
203
202
  def finish(name, id, payload)
204
- begin
205
- start_map = Thread.current[ApmBro::SqlSubscriber::THREAD_LOCAL_ALLOC_START_KEY]
206
- return unless start_map && start_map.key?(id)
207
-
208
- start_count = start_map.delete(id)
209
- end_count = (GC.stat[:total_allocated_objects] rescue nil)
210
- return unless start_count && end_count
211
-
212
- delta = end_count - start_count
213
- results = (Thread.current[ApmBro::SqlSubscriber::THREAD_LOCAL_ALLOC_RESULTS_KEY] ||= {})
214
- results[id] = delta
215
- rescue StandardError
203
+ start_map = Thread.current[ApmBro::SqlSubscriber::THREAD_LOCAL_ALLOC_START_KEY]
204
+ return unless start_map && start_map.key?(id)
205
+
206
+ start_count = start_map.delete(id)
207
+ end_count = begin
208
+ GC.stat[:total_allocated_objects]
209
+ rescue
210
+ nil
216
211
  end
212
+ return unless start_count && end_count
213
+
214
+ delta = end_count - start_count
215
+ results = (Thread.current[ApmBro::SqlSubscriber::THREAD_LOCAL_ALLOC_RESULTS_KEY] ||= {})
216
+ results[id] = delta
217
+ rescue
217
218
  end
218
219
  end
219
220
  end
@@ -12,37 +12,37 @@ module ApmBro
12
12
 
13
13
  # Start SQL tracking for this request
14
14
  if defined?(ApmBro::SqlSubscriber)
15
- puts "Starting SQL tracking for request: #{env['REQUEST_METHOD']} #{env['PATH_INFO']}"
15
+ puts "Starting SQL tracking for request: #{env["REQUEST_METHOD"]} #{env["PATH_INFO"]}"
16
16
  ApmBro::SqlSubscriber.start_request_tracking
17
17
  end
18
18
 
19
19
  # Start cache tracking for this request
20
20
  if defined?(ApmBro::CacheSubscriber)
21
- puts "Starting cache tracking for request: #{env['REQUEST_METHOD']} #{env['PATH_INFO']}"
21
+ puts "Starting cache tracking for request: #{env["REQUEST_METHOD"]} #{env["PATH_INFO"]}"
22
22
  ApmBro::CacheSubscriber.start_request_tracking
23
23
  end
24
24
 
25
25
  # Start Redis tracking for this request
26
26
  if defined?(ApmBro::RedisSubscriber)
27
- puts "Starting redis tracking for request: #{env['REQUEST_METHOD']} #{env['PATH_INFO']}"
27
+ puts "Starting redis tracking for request: #{env["REQUEST_METHOD"]} #{env["PATH_INFO"]}"
28
28
  ApmBro::RedisSubscriber.start_request_tracking
29
29
  end
30
30
 
31
31
  # Start view rendering tracking for this request
32
32
  if defined?(ApmBro::ViewRenderingSubscriber)
33
- puts "Starting view rendering tracking for request: #{env['REQUEST_METHOD']} #{env['PATH_INFO']}"
33
+ puts "Starting view rendering tracking for request: #{env["REQUEST_METHOD"]} #{env["PATH_INFO"]}"
34
34
  ApmBro::ViewRenderingSubscriber.start_request_tracking
35
35
  end
36
36
 
37
37
  # Start lightweight memory tracking for this request
38
38
  if defined?(ApmBro::LightweightMemoryTracker)
39
- puts "Starting lightweight memory tracking for request: #{env['REQUEST_METHOD']} #{env['PATH_INFO']}"
39
+ puts "Starting lightweight memory tracking for request: #{env["REQUEST_METHOD"]} #{env["PATH_INFO"]}"
40
40
  ApmBro::LightweightMemoryTracker.start_request_tracking
41
41
  end
42
42
 
43
43
  # Start detailed memory tracking when allocation tracking is enabled
44
44
  if ApmBro.configuration.allocation_tracking_enabled && defined?(ApmBro::MemoryTrackingSubscriber)
45
- puts "Starting detailed memory tracking for request: #{env['REQUEST_METHOD']} #{env['PATH_INFO']}"
45
+ puts "Starting detailed memory tracking for request: #{env["REQUEST_METHOD"]} #{env["PATH_INFO"]}"
46
46
  ApmBro::MemoryTrackingSubscriber.start_request_tracking
47
47
  end
48
48
 
@@ -53,27 +53,27 @@ module ApmBro
53
53
  ensure
54
54
  # Clean up thread-local storage
55
55
  if defined?(ApmBro::SqlSubscriber)
56
- queries = Thread.current[:apm_bro_sql_queries]
56
+ Thread.current[:apm_bro_sql_queries]
57
57
  Thread.current[:apm_bro_sql_queries] = nil
58
58
  end
59
59
 
60
60
  if defined?(ApmBro::CacheSubscriber)
61
- cache_events = Thread.current[:apm_bro_cache_events]
61
+ Thread.current[:apm_bro_cache_events]
62
62
  Thread.current[:apm_bro_cache_events] = nil
63
63
  end
64
64
 
65
65
  if defined?(ApmBro::RedisSubscriber)
66
- redis_events = Thread.current[:apm_bro_redis_events]
66
+ Thread.current[:apm_bro_redis_events]
67
67
  Thread.current[:apm_bro_redis_events] = nil
68
68
  end
69
69
 
70
70
  if defined?(ApmBro::ViewRenderingSubscriber)
71
- view_events = Thread.current[:apm_bro_view_events]
71
+ Thread.current[:apm_bro_view_events]
72
72
  Thread.current[:apm_bro_view_events] = nil
73
73
  end
74
74
 
75
75
  if defined?(ApmBro::LightweightMemoryTracker)
76
- memory_events = Thread.current[:apm_bro_lightweight_memory]
76
+ Thread.current[:apm_bro_lightweight_memory]
77
77
  Thread.current[:apm_bro_lightweight_memory] = nil
78
78
  end
79
79
 
@@ -4,7 +4,7 @@ require "active_support/notifications"
4
4
 
5
5
  module ApmBro
6
6
  class Subscriber
7
- EVENT_NAME = "process_action.action_controller".freeze
7
+ EVENT_NAME = "process_action.action_controller"
8
8
 
9
9
  def self.subscribe!(client: Client.new)
10
10
  ActiveSupport::Notifications.subscribe(EVENT_NAME) do |name, started, finished, _unique_id, data|
@@ -15,13 +15,13 @@ module ApmBro
15
15
  if ApmBro.configuration.excluded_controller_action?(controller_name, action_name)
16
16
  next
17
17
  end
18
- rescue StandardError
18
+ rescue
19
19
  end
20
20
 
21
21
  duration_ms = ((finished - started) * 1000.0).round(2)
22
22
  # Stop SQL tracking and get collected queries (this was started by the request)
23
23
  sql_queries = ApmBro::SqlSubscriber.stop_request_tracking
24
-
24
+
25
25
  # Stop cache and redis tracking
26
26
  cache_events = defined?(ApmBro::CacheSubscriber) ? ApmBro::CacheSubscriber.stop_request_tracking : []
27
27
  redis_events = defined?(ApmBro::RedisSubscriber) ? ApmBro::RedisSubscriber.stop_request_tracking : []
@@ -29,7 +29,7 @@ module ApmBro
29
29
  # Stop view rendering tracking and get collected view events
30
30
  view_events = ApmBro::ViewRenderingSubscriber.stop_request_tracking
31
31
  view_performance = ApmBro::ViewRenderingSubscriber.analyze_view_performance(view_events)
32
-
32
+
33
33
  # Stop memory tracking and get collected memory data
34
34
  if ApmBro.configuration.allocation_tracking_enabled && defined?(ApmBro::MemoryTrackingSubscriber)
35
35
  detailed_memory = ApmBro::MemoryTrackingSubscriber.stop_request_tracking
@@ -57,7 +57,7 @@ module ApmBro
57
57
  duration_seconds: lightweight_memory[:duration_seconds]
58
58
  }
59
59
  end
60
-
60
+
61
61
  # Record memory sample for leak detection (only if memory tracking enabled)
62
62
  if ApmBro.configuration.memory_tracking_enabled
63
63
  ApmBro::MemoryLeakDetector.record_memory_sample({
@@ -70,7 +70,7 @@ module ApmBro
70
70
  action: data[:action]
71
71
  })
72
72
  end
73
-
73
+
74
74
  # Report exceptions attached to this action (e.g. controller/view errors)
75
75
  if data[:exception] || data[:exception_object]
76
76
  begin
@@ -90,9 +90,8 @@ module ApmBro
90
90
  host: safe_host,
91
91
  params: safe_params(data),
92
92
  user_agent: safe_user_agent(data),
93
- user_email: extract_user_email(data),
94
93
  user_id: extract_user_id(data),
95
- exception_class: (exception_class || exception_obj&.class&.name),
94
+ exception_class: exception_class || exception_obj&.class&.name,
96
95
  message: (exception_message || exception_obj&.message).to_s[0, 1000],
97
96
  backtrace: backtrace,
98
97
  error: true,
@@ -101,7 +100,7 @@ module ApmBro
101
100
 
102
101
  event_name = (exception_class || exception_obj&.class&.name || "exception").to_s
103
102
  client.post_metric(event_name: event_name, payload: error_payload)
104
- rescue StandardError
103
+ rescue
105
104
  ensure
106
105
  next
107
106
  end
@@ -121,13 +120,12 @@ module ApmBro
121
120
  rails_env: rails_env,
122
121
  params: safe_params(data),
123
122
  user_agent: safe_user_agent(data),
124
- user_email: extract_user_email(data),
125
123
  user_id: extract_user_id(data),
126
124
  memory_usage: memory_usage_mb,
127
125
  gc_stats: gc_stats,
128
126
  sql_count: sql_count(data),
129
127
  sql_queries: sql_queries,
130
- http_outgoing: (Thread.current[:apm_bro_http_events] || []),
128
+ http_outgoing: Thread.current[:apm_bro_http_events] || [],
131
129
  cache_events: cache_events,
132
130
  redis_events: redis_events,
133
131
  cache_hits: cache_hits(data),
@@ -145,13 +143,17 @@ module ApmBro
145
143
  def self.safe_path(data)
146
144
  path = data[:path] || (data[:request] && data[:request].path)
147
145
  path.to_s
148
- rescue StandardError
146
+ rescue
149
147
  ""
150
148
  end
151
149
 
152
150
  def self.safe_host
153
151
  if defined?(Rails) && Rails.respond_to?(:application)
154
- Rails.application.class.module_parent_name rescue ""
152
+ begin
153
+ Rails.application.class.module_parent_name
154
+ rescue
155
+ ""
156
+ end
155
157
  else
156
158
  ""
157
159
  end
@@ -171,7 +173,7 @@ module ApmBro
171
173
  params = data[:params]
172
174
  begin
173
175
  params = params.to_unsafe_h if params.respond_to?(:to_unsafe_h)
174
- rescue StandardError
176
+ rescue
175
177
  end
176
178
 
177
179
  unless params.is_a?(Hash)
@@ -190,7 +192,7 @@ module ApmBro
190
192
 
191
193
  # Truncate deeply to keep payload small and safe
192
194
  truncate_value(filtered)
193
- rescue StandardError
195
+ rescue
194
196
  {}
195
197
  end
196
198
 
@@ -198,7 +200,7 @@ module ApmBro
198
200
  def self.truncate_value(value, max_str: 200, max_array: 20, max_hash_keys: 30)
199
201
  case value
200
202
  when String
201
- value.length > max_str ? value[0, max_str] + "…" : value
203
+ (value.length > max_str) ? value[0, max_str] + "…" : value
202
204
  when Numeric, TrueClass, FalseClass, NilClass
203
205
  value
204
206
  when Array
@@ -209,7 +211,7 @@ module ApmBro
209
211
  memo[k] = truncate_value(v, max_str: max_str, max_array: max_array, max_hash_keys: max_hash_keys)
210
212
  end
211
213
  else
212
- value.to_s.length > max_str ? value.to_s[0, max_str] + "…" : value.to_s
214
+ (value.to_s.length > max_str) ? value.to_s[0, max_str] + "…" : value.to_s
213
215
  end
214
216
  end
215
217
 
@@ -233,7 +235,11 @@ module ApmBro
233
235
  ua = headers["HTTP_USER_AGENT"] || headers["User-Agent"] || headers["user-agent"]
234
236
  return ua.to_s[0..200]
235
237
  elsif headers.respond_to?(:to_h)
236
- h = headers.to_h rescue {}
238
+ h = begin
239
+ headers.to_h
240
+ rescue
241
+ {}
242
+ end
237
243
  ua = h["HTTP_USER_AGENT"] || h["User-Agent"] || h["user-agent"]
238
244
  return ua.to_s[0..200]
239
245
  end
@@ -246,22 +252,26 @@ module ApmBro
246
252
  end
247
253
 
248
254
  ""
249
- rescue StandardError
255
+ rescue
250
256
  ""
251
257
  end
252
- rescue StandardError
258
+ rescue
253
259
  ""
254
260
  end
255
261
 
256
262
  def self.memory_usage_mb
257
263
  if defined?(GC) && GC.respond_to?(:stat)
258
264
  # Get memory usage in MB
259
- memory_kb = `ps -o rss= -p #{Process.pid}`.to_i rescue 0
265
+ memory_kb = begin
266
+ `ps -o rss= -p #{Process.pid}`.to_i
267
+ rescue
268
+ 0
269
+ end
260
270
  (memory_kb / 1024.0).round(2)
261
271
  else
262
272
  0
263
273
  end
264
- rescue StandardError
274
+ rescue
265
275
  0
266
276
  end
267
277
 
@@ -277,7 +287,7 @@ module ApmBro
277
287
  else
278
288
  {}
279
289
  end
280
- rescue StandardError
290
+ rescue
281
291
  {}
282
292
  end
283
293
 
@@ -287,11 +297,15 @@ module ApmBro
287
297
  data[:sql_count]
288
298
  elsif defined?(ActiveRecord) && ActiveRecord::Base.connection
289
299
  # Try to get from ActiveRecord connection
290
- ActiveRecord::Base.connection.query_cache.size rescue 0
300
+ begin
301
+ ActiveRecord::Base.connection.query_cache.size
302
+ rescue
303
+ 0
304
+ end
291
305
  else
292
306
  0
293
307
  end
294
- rescue StandardError
308
+ rescue
295
309
  0
296
310
  end
297
311
 
@@ -299,11 +313,15 @@ module ApmBro
299
313
  if data[:cache_hits]
300
314
  data[:cache_hits]
301
315
  elsif defined?(Rails) && Rails.cache.respond_to?(:stats)
302
- Rails.cache.stats[:hits] rescue 0
316
+ begin
317
+ Rails.cache.stats[:hits]
318
+ rescue
319
+ 0
320
+ end
303
321
  else
304
322
  0
305
323
  end
306
- rescue StandardError
324
+ rescue
307
325
  0
308
326
  end
309
327
 
@@ -311,26 +329,22 @@ module ApmBro
311
329
  if data[:cache_misses]
312
330
  data[:cache_misses]
313
331
  elsif defined?(Rails) && Rails.cache.respond_to?(:stats)
314
- Rails.cache.stats[:misses] rescue 0
332
+ begin
333
+ Rails.cache.stats[:misses]
334
+ rescue
335
+ 0
336
+ end
315
337
  else
316
338
  0
317
339
  end
318
- rescue StandardError
340
+ rescue
319
341
  0
320
342
  end
321
343
 
322
- def self.extract_user_email(data)
323
- data[:headers].env['warden'].user.email
324
- rescue StandardError
325
- nil
326
- end
327
-
328
344
  def self.extract_user_id(data)
329
- data[:headers].env['warden'].user.id
330
- rescue StandardError
345
+ data[:headers].env["warden"].user.id
346
+ rescue
331
347
  nil
332
348
  end
333
349
  end
334
350
  end
335
-
336
-
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ApmBro
4
- VERSION = "0.1.13"
4
+ VERSION = "0.1.15"
5
5
  end