Skip to content

Commit f728420

Browse files
committed
Reduce ActionCable broadcast metric cardinality
Previously, the metrics for Action Cable broadcast included the value for the broadcasting from the Active Support Notification payload. This value can have very high cardinality. Now, the metrics do not include the broadcasting value and are much simpler: "Ruby/ActionCable/broadcast"
1 parent e6a6f4a commit f728420

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# New Relic Ruby Agent Release Notes
22

3+
## dev
4+
5+
- **Bugfix: Reduce cardinality of ActionCable broadcast metrics**
6+
7+
Previously, the metrics for ActionCable broadcast included the value for the broadcasting. This value can have very high cardinality. Now, the metrics exclude the broadcasting value and are much simpler: `Ruby/ActionCable/broadcast`. (PR#XXXX)[link]
8+
39
## v10.2.0
410

511
- **Feature: Introduce Hybrid Agent for OpenTelemetry Tracing Support**

lib/new_relic/agent/instrumentation/action_cable_subscriber.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ def transaction_name_from_payload(payload)
2929
end
3030

3131
def metric_name_from_payload(name, payload)
32-
"Ruby/ActionCable/#{metric_name(payload)}/#{action_name(name)}"
32+
"Ruby/ActionCable/#{metric_name(payload)}#{action_name(name)}"
3333
end
3434

3535
def metric_name(payload)
36-
payload[:broadcasting] || payload[:channel_class]
36+
"#{payload[:channel_class]}/" if payload[:channel_class]
3737
end
3838

3939
DOT_ACTION_CABLE = '.action_cable'.freeze

test/new_relic/agent/instrumentation/rails/action_cable_subscriber.rb

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def test_does_not_record_unscoped_metrics_nor_create_trace_for_broadcast_outside
126126
sample = last_transaction_trace
127127

128128
assert_nil sample, 'Did not expect a transaction to be created for broadcast'
129-
refute_metrics_recorded ['Ruby/ActionCable/TestBroadcasting/broadcast']
129+
refute_metrics_recorded ['Ruby/ActionCable/broadcast']
130130
end
131131

132132
def test_actual_call_to_broadcast_method_records_segment_in_txn
@@ -136,15 +136,15 @@ def test_actual_call_to_broadcast_method_records_segment_in_txn
136136
@subscriber.finish('broadcast.action_cable', :id, payload_for_broadcast)
137137
end
138138

139-
metric_name = 'Ruby/ActionCable/TestBroadcasting/broadcast'
139+
metric_name = 'Ruby/ActionCable/broadcast'
140140

141141
assert_metrics_recorded metric_name
142142
assert find_node_with_name(last_transaction_trace, metric_name),
143143
'Could not find a node with desired name.'
144144
end
145145

146-
def test_metric_name_correctly_names_payload_for_broadcast
147-
assert_equal 'TestBroadcasting', @subscriber.send(:metric_name, payload_for_broadcast)
146+
def test_metric_name_returns_nil_for_payload_from_broadcast
147+
assert_nil @subscriber.send(:metric_name, payload_for_broadcast)
148148
end
149149

150150
def test_metric_name_correctly_names_payload_for_channel
@@ -200,10 +200,21 @@ def payload_for_transmit(data = {}, via = nil)
200200
end
201201

202202
def payload_for_broadcast
203-
{
204-
broadcasting: 'TestBroadcasting',
205-
message: {message: 'test_message'},
206-
coder: 'idk-we-dont-save-this'
203+
{broadcasting: "tasks_964944192",
204+
message:
205+
{
206+
action: "created",
207+
task:
208+
{"id" => 629957653,
209+
"name" => "Go for a run",
210+
"description" => "Week 9 C25k",
211+
"created_at" =>
212+
"2026-02-18T21:47:55.096Z",
213+
"updated_at" =>
214+
"2026-02-18T21:47:55.096Z",
215+
"status" => "in_progress",
216+
"group_id" => 964944192}
217+
}
207218
}
208219
end
209220
end

0 commit comments

Comments
 (0)