apm_bro 0.1.14 → 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.
@@ -5,17 +5,17 @@ require "active_support/notifications"
5
5
  module ApmBro
6
6
  class ViewRenderingSubscriber
7
7
  # Rails view rendering events
8
- RENDER_TEMPLATE_EVENT = "render_template.action_view".freeze
9
- RENDER_PARTIAL_EVENT = "render_partial.action_view".freeze
10
- RENDER_COLLECTION_EVENT = "render_collection.action_view".freeze
11
-
8
+ RENDER_TEMPLATE_EVENT = "render_template.action_view"
9
+ RENDER_PARTIAL_EVENT = "render_partial.action_view"
10
+ RENDER_COLLECTION_EVENT = "render_collection.action_view"
11
+
12
12
  THREAD_LOCAL_KEY = :apm_bro_view_events
13
13
 
14
14
  def self.subscribe!(client: Client.new)
15
15
  # Track template rendering
16
16
  ActiveSupport::Notifications.subscribe(RENDER_TEMPLATE_EVENT) do |name, started, finished, _unique_id, data|
17
17
  duration_ms = ((finished - started) * 1000.0).round(2)
18
-
18
+
19
19
  view_info = {
20
20
  type: "template",
21
21
  identifier: safe_identifier(data[:identifier]),
@@ -24,14 +24,14 @@ module ApmBro
24
24
  virtual_path: data[:virtual_path],
25
25
  rendered_at: Time.now.utc.to_i
26
26
  }
27
-
27
+
28
28
  add_view_event(view_info)
29
29
  end
30
30
 
31
31
  # Track partial rendering
32
32
  ActiveSupport::Notifications.subscribe(RENDER_PARTIAL_EVENT) do |name, started, finished, _unique_id, data|
33
33
  duration_ms = ((finished - started) * 1000.0).round(2)
34
-
34
+
35
35
  view_info = {
36
36
  type: "partial",
37
37
  identifier: safe_identifier(data[:identifier]),
@@ -41,14 +41,14 @@ module ApmBro
41
41
  cache_key: data[:cache_key],
42
42
  rendered_at: Time.now.utc.to_i
43
43
  }
44
-
44
+
45
45
  add_view_event(view_info)
46
46
  end
47
47
 
48
48
  # Track collection rendering (for partials rendered in loops)
49
49
  ActiveSupport::Notifications.subscribe(RENDER_COLLECTION_EVENT) do |name, started, finished, _unique_id, data|
50
50
  duration_ms = ((finished - started) * 1000.0).round(2)
51
-
51
+
52
52
  view_info = {
53
53
  type: "collection",
54
54
  identifier: safe_identifier(data[:identifier]),
@@ -60,10 +60,10 @@ module ApmBro
60
60
  cached_count: data[:cached_count],
61
61
  rendered_at: Time.now.utc.to_i
62
62
  }
63
-
63
+
64
64
  add_view_event(view_info)
65
65
  end
66
- rescue StandardError
66
+ rescue
67
67
  # Never raise from instrumentation install
68
68
  end
69
69
 
@@ -85,11 +85,11 @@ module ApmBro
85
85
 
86
86
  def self.safe_identifier(identifier)
87
87
  return "" unless identifier.is_a?(String)
88
-
88
+
89
89
  # Extract meaningful parts of the file path
90
90
  # e.g., "/app/views/users/show.html.erb" -> "users/show.html.erb"
91
91
  identifier.split("/").last(3).join("/")
92
- rescue StandardError
92
+ rescue
93
93
  identifier.to_s
94
94
  end
95
95
 
@@ -98,29 +98,29 @@ module ApmBro
98
98
  return {} if view_events.empty?
99
99
 
100
100
  total_duration = view_events.sum { |event| event[:duration_ms] }
101
-
101
+
102
102
  # Group by view type
103
103
  by_type = view_events.group_by { |event| event[:type] }
104
-
104
+
105
105
  # Find slowest views
106
106
  slowest_views = view_events.sort_by { |event| -event[:duration_ms] }.first(5)
107
-
107
+
108
108
  # Find most frequently rendered views
109
109
  view_frequency = view_events.group_by { |event| event[:identifier] }
110
- .transform_values(&:count)
111
- .sort_by { |_, count| -count }
112
- .first(5)
113
-
110
+ .transform_values(&:count)
111
+ .sort_by { |_, count| -count }
112
+ .first(5)
113
+
114
114
  # Calculate cache hit rates for partials
115
115
  partials = view_events.select { |event| event[:type] == "partial" }
116
116
  cache_hits = partials.count { |event| event[:cache_key] }
117
117
  cache_hit_rate = partials.any? ? (cache_hits.to_f / partials.count * 100).round(2) : 0
118
-
118
+
119
119
  # Collection rendering analysis
120
120
  collections = view_events.select { |event| event[:type] == "collection" }
121
121
  total_collection_items = collections.sum { |event| event[:count] || 0 }
122
122
  total_cached_items = collections.sum { |event| event[:cached_count] || 0 }
123
- collection_cache_hit_rate = total_collection_items > 0 ?
123
+ collection_cache_hit_rate = (total_collection_items > 0) ?
124
124
  (total_cached_items.to_f / total_collection_items * 100).round(2) : 0
125
125
 
126
126
  {
@@ -128,7 +128,7 @@ module ApmBro
128
128
  total_view_duration_ms: total_duration.round(2),
129
129
  average_view_duration_ms: (total_duration / view_events.count).round(2),
130
130
  by_type: by_type.transform_values(&:count),
131
- slowest_views: slowest_views.map { |view|
131
+ slowest_views: slowest_views.map { |view|
132
132
  {
133
133
  identifier: view[:identifier],
134
134
  duration_ms: view[:duration_ms],
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apm_bro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emanuel Comsa
@@ -40,11 +40,11 @@ files:
40
40
  - lib/apm_bro/subscriber.rb
41
41
  - lib/apm_bro/version.rb
42
42
  - lib/apm_bro/view_rendering_subscriber.rb
43
- homepage: https://github.com/rubydev/apm_bro
43
+ homepage: https://www.deadbro.com
44
44
  licenses: []
45
45
  metadata:
46
- homepage_uri: https://github.com/rubydev/apm_bro
47
- source_code_uri: https://github.com/rubydev/apm_bro
46
+ homepage_uri: https://www.deadbro.com
47
+ source_code_uri: https://github.com/rubydevro/apm_bro
48
48
  rdoc_options: []
49
49
  require_paths:
50
50
  - lib