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.
- checksums.yaml +4 -4
- data/README.md +0 -35
- data/lib/apm_bro/cache_subscriber.rb +15 -25
- data/lib/apm_bro/circuit_breaker.rb +9 -17
- data/lib/apm_bro/client.rb +28 -36
- data/lib/apm_bro/configuration.rb +44 -62
- data/lib/apm_bro/error_middleware.rb +16 -30
- data/lib/apm_bro/http_instrumentation.rb +22 -16
- data/lib/apm_bro/job_sql_tracking_middleware.rb +1 -1
- data/lib/apm_bro/job_subscriber.rb +41 -25
- data/lib/apm_bro/lightweight_memory_tracker.rb +8 -8
- data/lib/apm_bro/logger.rb +8 -9
- data/lib/apm_bro/memory_helpers.rb +13 -13
- data/lib/apm_bro/memory_leak_detector.rb +37 -37
- data/lib/apm_bro/memory_tracking_subscriber.rb +62 -54
- data/lib/apm_bro/railtie.rb +28 -30
- data/lib/apm_bro/redis_subscriber.rb +34 -37
- data/lib/apm_bro/sql_subscriber.rb +60 -59
- data/lib/apm_bro/sql_tracking_middleware.rb +11 -11
- data/lib/apm_bro/subscriber.rb +53 -39
- data/lib/apm_bro/version.rb +1 -1
- data/lib/apm_bro/view_rendering_subscriber.rb +23 -23
- metadata +4 -4
|
@@ -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"
|
|
9
|
-
RENDER_PARTIAL_EVENT = "render_partial.action_view"
|
|
10
|
-
RENDER_COLLECTION_EVENT = "render_collection.action_view"
|
|
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
|
|
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
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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.
|
|
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://
|
|
43
|
+
homepage: https://www.deadbro.com
|
|
44
44
|
licenses: []
|
|
45
45
|
metadata:
|
|
46
|
-
homepage_uri: https://
|
|
47
|
-
source_code_uri: https://github.com/
|
|
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
|