|
187 | 187 | expect(metric).to be_a(Sentry::Metrics::SetMetric)
|
188 | 188 | expect(metric.value).to eq(Set[1])
|
189 | 189 | end
|
| 190 | + |
| 191 | + describe 'local aggregation for span metric summaries' do |
| 192 | + it 'does nothing without an active scope span' do |
| 193 | + expect_any_instance_of(Sentry::Metrics::LocalAggregator).not_to receive(:add) |
| 194 | + subject.add(:c, 'incr', 1) |
| 195 | + end |
| 196 | + |
| 197 | + context 'with running transaction and active span' do |
| 198 | + let(:span) { Sentry.start_transaction } |
| 199 | + |
| 200 | + before do |
| 201 | + Sentry.get_current_scope.set_span(span) |
| 202 | + Sentry.get_current_scope.set_transaction_name('metric', source: :view) |
| 203 | + end |
| 204 | + |
| 205 | + it 'does nothing if transaction name is low quality' do |
| 206 | + expect_any_instance_of(Sentry::Metrics::LocalAggregator).not_to receive(:add) |
| 207 | + |
| 208 | + Sentry.get_current_scope.set_transaction_name('/123', source: :url) |
| 209 | + subject.add(:c, 'incr', 1) |
| 210 | + end |
| 211 | + |
| 212 | + it 'proxies bucket key and value to local aggregator' do |
| 213 | + expect(span.metrics_local_aggregator).to receive(:add).with( |
| 214 | + array_including(:c, 'incr', 'none'), |
| 215 | + 1 |
| 216 | + ) |
| 217 | + subject.add(:c, 'incr', 1) |
| 218 | + end |
| 219 | + |
| 220 | + context 'for set metrics' do |
| 221 | + before { subject.add(:s, 'set', 'foo') } |
| 222 | + |
| 223 | + it 'proxies bucket key and value 0 when existing element' do |
| 224 | + expect(span.metrics_local_aggregator).to receive(:add).with( |
| 225 | + array_including(:s, 'set', 'none'), |
| 226 | + 0 |
| 227 | + ) |
| 228 | + subject.add(:s, 'set', 'foo') |
| 229 | + end |
| 230 | + |
| 231 | + it 'proxies bucket key and value 1 when new element' do |
| 232 | + expect(span.metrics_local_aggregator).to receive(:add).with( |
| 233 | + array_including(:s, 'set', 'none'), |
| 234 | + 1 |
| 235 | + ) |
| 236 | + subject.add(:s, 'set', 'bar') |
| 237 | + end |
| 238 | + end |
| 239 | + end |
| 240 | + end |
190 | 241 | end
|
191 | 242 |
|
192 | 243 | describe '#flush' do
|
|
0 commit comments