|
20 | 20 | let(:block_result) { 'test_result' } |
21 | 21 | let(:test_block) { -> { block_result } } |
22 | 22 |
|
23 | | - context 'when neither AppSignal nor Sentry is enabled' do |
| 23 | + context 'when AppSignal is not enabled' do |
24 | 24 | before do |
25 | 25 | Idempotency.configure do |config| |
26 | 26 | config.redis_pool = redis_pool |
27 | 27 | config.logger = Logger.new(nil) |
28 | 28 | config.observability.appsignal_enabled = false |
29 | | - config.observability.sentry_enabled = false |
30 | 29 | end |
31 | 30 | end |
32 | 31 |
|
|
48 | 47 | config.redis_pool = redis_pool |
49 | 48 | config.logger = Logger.new(nil) |
50 | 49 | config.observability.appsignal_enabled = true |
51 | | - config.observability.sentry_enabled = false |
52 | 50 | end |
53 | 51 | end |
54 | 52 |
|
|
97 | 95 | end |
98 | 96 | end |
99 | 97 |
|
100 | | - context 'when Sentry is enabled' do |
101 | | - let(:mock_span) { double('Sentry::Span') } |
102 | | - |
103 | | - before do |
104 | | - stub_const('Sentry', double('Sentry')) |
105 | | - allow(Sentry).to receive(:with_child_span).and_yield(mock_span) |
106 | | - |
107 | | - Idempotency.configure do |config| |
108 | | - config.redis_pool = redis_pool |
109 | | - config.logger = Logger.new(nil) |
110 | | - config.observability.appsignal_enabled = false |
111 | | - config.observability.sentry_enabled = true |
112 | | - end |
113 | | - end |
114 | | - |
115 | | - it 'wraps execution in Sentry child span' do |
116 | | - expect(Sentry).to receive(:with_child_span).with( |
117 | | - op: 'test.operation', |
118 | | - description: 'test' |
119 | | - ).and_yield(mock_span) |
120 | | - |
121 | | - result = idempotency.send(:with_apm_instrumentation, 'test.operation', 'test') do |
122 | | - test_block.call |
123 | | - end |
124 | | - |
125 | | - expect(result).to eq(block_result) |
126 | | - end |
127 | | - |
128 | | - it 'captures exceptions with Sentry and re-raises' do |
129 | | - test_error = StandardError.new('test error') |
130 | | - |
131 | | - expect(Sentry).to receive(:with_child_span).with( |
132 | | - op: 'test.operation', |
133 | | - description: 'test' |
134 | | - ).and_yield(mock_span) |
135 | | - |
136 | | - expect(Sentry).to receive(:capture_exception).with(test_error) |
137 | | - |
138 | | - expect do |
139 | | - idempotency.send(:with_apm_instrumentation, 'test.operation', 'test') do |
140 | | - raise test_error |
141 | | - end |
142 | | - end.to raise_error(StandardError, 'test error') |
143 | | - end |
144 | | - end |
145 | | - |
146 | 98 | context 'when AppSignal is enabled but not defined' do |
147 | 99 | before do |
148 | 100 | hide_const('Appsignal') |
|
151 | 103 | config.redis_pool = redis_pool |
152 | 104 | config.logger = Logger.new(nil) |
153 | 105 | config.observability.appsignal_enabled = true |
154 | | - config.observability.sentry_enabled = false |
155 | | - end |
156 | | - end |
157 | | - |
158 | | - it 'falls back to executing without instrumentation' do |
159 | | - result = idempotency.send(:with_apm_instrumentation, 'test.operation', 'test') do |
160 | | - test_block.call |
161 | | - end |
162 | | - |
163 | | - expect(result).to eq(block_result) |
164 | | - end |
165 | | - end |
166 | | - |
167 | | - context 'when Sentry is enabled but not defined' do |
168 | | - before do |
169 | | - hide_const('Sentry') |
170 | | - |
171 | | - Idempotency.configure do |config| |
172 | | - config.redis_pool = redis_pool |
173 | | - config.logger = Logger.new(nil) |
174 | | - config.observability.appsignal_enabled = false |
175 | | - config.observability.sentry_enabled = true |
176 | 106 | end |
177 | 107 | end |
178 | 108 |
|
|
184 | 114 | expect(result).to eq(block_result) |
185 | 115 | end |
186 | 116 | end |
187 | | - |
188 | | - context 'when both AppSignal and Sentry are enabled' do |
189 | | - let(:mock_span) { double('Sentry::Span') } |
190 | | - |
191 | | - before do |
192 | | - stub_const('Appsignal', double('Appsignal')) |
193 | | - stub_const('Sentry', double('Sentry')) |
194 | | - allow(Appsignal).to receive(:instrument).and_yield |
195 | | - allow(Sentry).to receive(:with_child_span).and_yield(mock_span) |
196 | | - |
197 | | - Idempotency.configure do |config| |
198 | | - config.redis_pool = redis_pool |
199 | | - config.logger = Logger.new(nil) |
200 | | - config.observability.appsignal_enabled = true |
201 | | - config.observability.sentry_enabled = true |
202 | | - end |
203 | | - end |
204 | | - |
205 | | - it 'instruments in both AppSignal and Sentry (nested)' do |
206 | | - # Expect Sentry to be set up (inner layer) |
207 | | - expect(Sentry).to receive(:with_child_span).with( |
208 | | - op: 'test.operation', |
209 | | - description: 'test' |
210 | | - ).and_yield(mock_span) |
211 | | - |
212 | | - # Expect AppSignal to wrap everything (outer layer) |
213 | | - expect(Appsignal).to receive(:instrument).with( |
214 | | - 'test.operation', |
215 | | - 'test' |
216 | | - ).and_yield |
217 | | - |
218 | | - result = idempotency.send(:with_apm_instrumentation, 'test.operation', 'test') do |
219 | | - test_block.call |
220 | | - end |
221 | | - |
222 | | - expect(result).to eq(block_result) |
223 | | - end |
224 | | - |
225 | | - it 'reports errors to both AppSignal and Sentry' do |
226 | | - test_error = StandardError.new('test error') |
227 | | - |
228 | | - # Expect Sentry to capture the exception (inner layer) |
229 | | - expect(Sentry).to receive(:with_child_span).with( |
230 | | - op: 'test.operation', |
231 | | - description: 'test' |
232 | | - ).and_yield(mock_span) |
233 | | - expect(Sentry).to receive(:capture_exception).with(test_error) |
234 | | - |
235 | | - # Expect AppSignal to also capture the exception (outer layer) |
236 | | - expect(Appsignal).to receive(:instrument).with( |
237 | | - 'test.operation', |
238 | | - 'test' |
239 | | - ).and_yield |
240 | | - expect(Appsignal).to receive(:set_error).with(test_error) |
241 | | - |
242 | | - expect do |
243 | | - idempotency.send(:with_apm_instrumentation, 'test.operation', 'test') do |
244 | | - raise test_error |
245 | | - end |
246 | | - end.to raise_error(StandardError, 'test error') |
247 | | - end |
248 | | - end |
249 | 117 | end |
250 | 118 | end |
0 commit comments