|
214 | 214 | end |
215 | 215 | end |
216 | 216 |
|
| 217 | + context "byte-count client outcomes" do |
| 218 | + let(:log_events) do |
| 219 | + 3.times.map do |
| 220 | + Sentry::LogEvent.new(level: :info, body: "User has logged in!") |
| 221 | + end |
| 222 | + end |
| 223 | + |
| 224 | + let(:metric_events) do |
| 225 | + 3.times.map do |
| 226 | + Sentry::MetricEvent.new(name: "my.metric", type: "counter", value: 1) |
| 227 | + end |
| 228 | + end |
| 229 | + |
| 230 | + let(:log_envelope) do |
| 231 | + envelope = Sentry::Envelope.new |
| 232 | + envelope.add_item( |
| 233 | + { type: "log", item_count: log_events.size, content_type: "application/vnd.sentry.items.log+json" }, |
| 234 | + { items: log_events.map(&:to_h) } |
| 235 | + ) |
| 236 | + envelope |
| 237 | + end |
| 238 | + |
| 239 | + let(:metric_envelope) do |
| 240 | + envelope = Sentry::Envelope.new |
| 241 | + envelope.add_item( |
| 242 | + { type: "trace_metric", item_count: metric_events.size, content_type: "application/vnd.sentry.items.trace-metric+json" }, |
| 243 | + { items: metric_events.map(&:to_h) } |
| 244 | + ) |
| 245 | + envelope |
| 246 | + end |
| 247 | + |
| 248 | + describe "#record_lost_event" do |
| 249 | + it "fans out into the paired byte category" do |
| 250 | + subject.record_lost_event(:ratelimit_backoff, "log_item", num: 3, num_bytes: 1243) |
| 251 | + |
| 252 | + expect(subject.discarded_events[[:ratelimit_backoff, "log_item"]]).to eq(3) |
| 253 | + expect(subject.discarded_events[[:ratelimit_backoff, "log_byte"]]).to eq(1243) |
| 254 | + end |
| 255 | + |
| 256 | + it "does not record a byte category for non-byte-tracked categories" do |
| 257 | + subject.record_lost_event(:ratelimit_backoff, "error", num: 1, num_bytes: 1243) |
| 258 | + |
| 259 | + expect(subject.discarded_events.keys).to contain_exactly([:ratelimit_backoff, "error"]) |
| 260 | + end |
| 261 | + |
| 262 | + it "does not record bytes when num_bytes is nil" do |
| 263 | + subject.record_lost_event(:ratelimit_backoff, "log_item") |
| 264 | + |
| 265 | + expect(subject.discarded_events.keys).to contain_exactly([:ratelimit_backoff, "log_item"]) |
| 266 | + end |
| 267 | + end |
| 268 | + |
| 269 | + context "when a batched log item is rate limited" do |
| 270 | + before { subject.rate_limits.merge!("log_item" => Time.now + 60) } |
| 271 | + |
| 272 | + it "records log_item count and log_byte size" do |
| 273 | + log_item = log_envelope.items.first |
| 274 | + subject.send_envelope(log_envelope) |
| 275 | + |
| 276 | + expect(subject.discarded_events[[:ratelimit_backoff, "log_item"]]).to eq(3) |
| 277 | + expect(subject.discarded_events[[:ratelimit_backoff, "log_byte"]]).to eq(JSON.generate(log_item.payload).bytesize) |
| 278 | + end |
| 279 | + end |
| 280 | + |
| 281 | + context "when a batched trace metric item is rate limited" do |
| 282 | + before { subject.rate_limits.merge!("trace_metric" => Time.now + 60) } |
| 283 | + |
| 284 | + it "records trace_metric count and trace_metric_byte size" do |
| 285 | + metric_item = metric_envelope.items.first |
| 286 | + subject.send_envelope(metric_envelope) |
| 287 | + |
| 288 | + expect(subject.discarded_events[[:ratelimit_backoff, "trace_metric"]]).to eq(3) |
| 289 | + expect(subject.discarded_events[[:ratelimit_backoff, "trace_metric_byte"]]).to eq(JSON.generate(metric_item.payload).bytesize) |
| 290 | + end |
| 291 | + end |
| 292 | + end |
| 293 | + |
217 | 294 | context "log events" do |
218 | 295 | let(:log_events) do |
219 | 296 | 5.times.map do |i| |
|
0 commit comments