|
2 | 2 | require "spec_helper" |
3 | 3 | require "action_cable/engine" |
4 | 4 |
|
| 5 | + ::ActionCable.server.config.cable = { "adapter" => "test" } |
| 6 | + |
5 | 7 | # ensure we can access `connection.env` in tests like we can in production |
6 | 8 | ActiveSupport.on_load :action_cable_channel_test_case do |
7 | 9 | class ::ActionCable::Channel::ConnectionStub |
@@ -30,73 +32,191 @@ def unsubscribed |
30 | 32 | RSpec.describe "Sentry::Rails::ActionCableExtensions", type: :channel do |
31 | 33 | let(:transport) { Sentry.get_current_client.transport } |
32 | 34 |
|
33 | | - before(:all) do |
34 | | - make_basic_app |
35 | | - ::ActionCable.server.config.cable = { "adapter" => "test" } |
36 | | - end |
37 | | - |
38 | 35 | after do |
39 | 36 | transport.events = [] |
40 | 37 | end |
41 | 38 |
|
42 | | - describe ChatChannel do |
43 | | - it "captures errors during the subscribe" do |
44 | | - expect { subscribe room_id: 42 }.to raise_error('foo') |
45 | | - expect(transport.events.count).to eq(1) |
| 39 | + context "without tracing" do |
| 40 | + before do |
| 41 | + make_basic_app |
| 42 | + end |
| 43 | + |
| 44 | + describe ChatChannel do |
| 45 | + it "captures errors during the subscribe" do |
| 46 | + expect { subscribe room_id: 42 }.to raise_error('foo') |
| 47 | + expect(transport.events.count).to eq(1) |
46 | 48 |
|
47 | | - event = transport.events.last.to_json_compatible |
| 49 | + event = transport.events.last.to_json_compatible |
| 50 | + expect(event["transaction"]).to eq("ChatChannel#subscribed") |
| 51 | + expect(event["contexts"]).to include("action_cable" => { "params" => { "room_id" => 42 } }) |
| 52 | + end |
| 53 | + end |
48 | 54 |
|
49 | | - expect(event).to include( |
50 | | - "transaction" => "ChatChannel#subscribed", |
51 | | - "extra" => { |
| 55 | + describe AppearanceChannel do |
| 56 | + before { subscribe room_id: 42 } |
| 57 | + |
| 58 | + it "captures errors during the action" do |
| 59 | + expect { perform :appear, foo: 'bar' }.to raise_error('foo') |
| 60 | + expect(transport.events.count).to eq(1) |
| 61 | + |
| 62 | + event = transport.events.last.to_json_compatible |
| 63 | + |
| 64 | + expect(event["transaction"]).to eq("AppearanceChannel#appear") |
| 65 | + expect(event["contexts"]).to include( |
52 | 66 | "action_cable" => { |
53 | | - "params" => { "room_id" => 42 } |
| 67 | + "params" => { "room_id" => 42 }, |
| 68 | + "data" => { "action" => "appear", "foo" => "bar" } |
54 | 69 | } |
55 | | - } |
56 | | - ) |
| 70 | + ) |
| 71 | + end |
| 72 | + |
| 73 | + it "captures errors during unsubscribe" do |
| 74 | + expect { unsubscribe }.to raise_error('foo') |
| 75 | + expect(transport.events.count).to eq(1) |
| 76 | + |
| 77 | + event = transport.events.last.to_json_compatible |
57 | 78 |
|
58 | | - expect(Sentry.get_current_scope.extra).to eq({}) |
| 79 | + expect(event["transaction"]).to eq("AppearanceChannel#unsubscribed") |
| 80 | + expect(event["contexts"]).to include( |
| 81 | + "action_cable" => { |
| 82 | + "params" => { "room_id" => 42 } |
| 83 | + } |
| 84 | + ) |
| 85 | + end |
59 | 86 | end |
60 | 87 | end |
61 | 88 |
|
62 | | - describe AppearanceChannel do |
63 | | - before { subscribe room_id: 42 } |
| 89 | + context "with tracing enabled" do |
| 90 | + before do |
| 91 | + make_basic_app do |config| |
| 92 | + config.traces_sample_rate = 1.0 |
| 93 | + end |
| 94 | + end |
| 95 | + |
| 96 | + describe ChatChannel do |
| 97 | + it "captures errors and transactions during the subscribe" do |
| 98 | + expect { subscribe room_id: 42 }.to raise_error('foo') |
| 99 | + expect(transport.events.count).to eq(2) |
| 100 | + |
| 101 | + event = transport.events.first.to_json_compatible |
64 | 102 |
|
65 | | - it "captures errors during the action" do |
66 | | - expect { perform :appear, foo: 'bar' }.to raise_error('foo') |
67 | | - expect(transport.events.count).to eq(1) |
| 103 | + expect(event["transaction"]).to eq("ChatChannel#subscribed") |
| 104 | + expect(event["contexts"]).to include("action_cable" => { "params" => { "room_id" => 42 } }) |
68 | 105 |
|
69 | | - event = transport.events.last.to_json_compatible |
| 106 | + transaction = transport.events.last.to_json_compatible |
70 | 107 |
|
71 | | - expect(event).to include( |
72 | | - "transaction" => "AppearanceChannel#appear", |
73 | | - "extra" => { |
| 108 | + expect(transaction["type"]).to eq("transaction") |
| 109 | + expect(transaction["transaction"]).to eq("ChatChannel#subscribed") |
| 110 | + expect(transaction["contexts"]).to include( |
| 111 | + "action_cable" => { |
| 112 | + "params" => { "room_id" => 42 } |
| 113 | + } |
| 114 | + ) |
| 115 | + expect(transaction["contexts"]).to include( |
| 116 | + "trace" => hash_including( |
| 117 | + "op" => "rails.action_cable", |
| 118 | + "status" => "internal_error" |
| 119 | + ) |
| 120 | + ) |
| 121 | + end |
| 122 | + end |
| 123 | + |
| 124 | + describe AppearanceChannel do |
| 125 | + before { subscribe room_id: 42 } |
| 126 | + |
| 127 | + it "captures errors and transactions during the action" do |
| 128 | + expect { perform :appear, foo: 'bar' }.to raise_error('foo') |
| 129 | + expect(transport.events.count).to eq(3) |
| 130 | + |
| 131 | + subscription_transaction = transport.events[0].to_json_compatible |
| 132 | + |
| 133 | + expect(subscription_transaction["type"]).to eq("transaction") |
| 134 | + expect(subscription_transaction["transaction"]).to eq("AppearanceChannel#subscribed") |
| 135 | + expect(subscription_transaction["contexts"]).to include( |
| 136 | + "action_cable" => { |
| 137 | + "params" => { "room_id" => 42 } |
| 138 | + } |
| 139 | + ) |
| 140 | + expect(subscription_transaction["contexts"]).to include( |
| 141 | + "trace" => hash_including( |
| 142 | + "op" => "rails.action_cable", |
| 143 | + "status" => "ok" |
| 144 | + ) |
| 145 | + ) |
| 146 | + |
| 147 | + event = transport.events[1].to_json_compatible |
| 148 | + |
| 149 | + expect(event["transaction"]).to eq("AppearanceChannel#appear") |
| 150 | + expect(event["contexts"]).to include( |
74 | 151 | "action_cable" => { |
75 | 152 | "params" => { "room_id" => 42 }, |
76 | 153 | "data" => { "action" => "appear", "foo" => "bar" } |
77 | 154 | } |
78 | | - } |
79 | | - ) |
| 155 | + ) |
80 | 156 |
|
81 | | - expect(Sentry.get_current_scope.extra).to eq({}) |
82 | | - end |
| 157 | + action_transaction = transport.events[2].to_json_compatible |
83 | 158 |
|
84 | | - it "captures errors during unsubscribe" do |
85 | | - expect { unsubscribe }.to raise_error('foo') |
86 | | - expect(transport.events.count).to eq(1) |
| 159 | + expect(action_transaction["type"]).to eq("transaction") |
| 160 | + expect(action_transaction["transaction"]).to eq("AppearanceChannel#appear") |
| 161 | + expect(action_transaction["contexts"]).to include( |
| 162 | + "action_cable" => { |
| 163 | + "params" => { "room_id" => 42 }, |
| 164 | + "data" => { "action" => "appear", "foo" => "bar" } |
| 165 | + } |
| 166 | + ) |
| 167 | + expect(action_transaction["contexts"]).to include( |
| 168 | + "trace" => hash_including( |
| 169 | + "op" => "rails.action_cable", |
| 170 | + "status" => "internal_error" |
| 171 | + ) |
| 172 | + ) |
| 173 | + end |
| 174 | + |
| 175 | + it "captures errors during unsubscribe" do |
| 176 | + expect { unsubscribe }.to raise_error('foo') |
| 177 | + expect(transport.events.count).to eq(3) |
| 178 | + |
| 179 | + subscription_transaction = transport.events[0].to_json_compatible |
| 180 | + |
| 181 | + expect(subscription_transaction["type"]).to eq("transaction") |
| 182 | + expect(subscription_transaction["transaction"]).to eq("AppearanceChannel#subscribed") |
| 183 | + expect(subscription_transaction["contexts"]).to include( |
| 184 | + "action_cable" => { |
| 185 | + "params" => { "room_id" => 42 } |
| 186 | + } |
| 187 | + ) |
| 188 | + expect(subscription_transaction["contexts"]).to include( |
| 189 | + "trace" => hash_including( |
| 190 | + "op" => "rails.action_cable", |
| 191 | + "status" => "ok" |
| 192 | + ) |
| 193 | + ) |
| 194 | + |
| 195 | + event = transport.events[1].to_json_compatible |
| 196 | + |
| 197 | + expect(event["transaction"]).to eq("AppearanceChannel#unsubscribed") |
| 198 | + expect(event["contexts"]).to include( |
| 199 | + "action_cable" => { |
| 200 | + "params" => { "room_id" => 42 } |
| 201 | + } |
| 202 | + ) |
87 | 203 |
|
88 | | - event = transport.events.last.to_json_compatible |
| 204 | + transaction = transport.events[2].to_json_compatible |
89 | 205 |
|
90 | | - expect(event).to include( |
91 | | - "transaction" => "AppearanceChannel#unsubscribed", |
92 | | - "extra" => { |
| 206 | + expect(transaction["type"]).to eq("transaction") |
| 207 | + expect(transaction["transaction"]).to eq("AppearanceChannel#unsubscribed") |
| 208 | + expect(transaction["contexts"]).to include( |
93 | 209 | "action_cable" => { |
94 | 210 | "params" => { "room_id" => 42 } |
95 | 211 | } |
96 | | - } |
97 | | - ) |
98 | | - |
99 | | - expect(Sentry.get_current_scope.extra).to eq({}) |
| 212 | + ) |
| 213 | + expect(transaction["contexts"]).to include( |
| 214 | + "trace" => hash_including( |
| 215 | + "op" => "rails.action_cable", |
| 216 | + "status" => "internal_error" |
| 217 | + ) |
| 218 | + ) |
| 219 | + end |
100 | 220 | end |
101 | 221 | end |
102 | 222 | end |
|
0 commit comments