-
Notifications
You must be signed in to change notification settings - Fork 648
feat(batcher): Add global flush trigger based on summed size estimates #7144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b429f5f
b30af99
bde3c70
684d524
902b89a
2f6611f
faf5684
4c684a4
5a295fa
f6acf15
9cd2102
548409d
8d9b2b1
75fc7df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -338,6 +338,69 @@ | |
| assert envelopes[0].items[0].payload.json["items"][1]["name"] == "big span" | ||
|
|
||
|
|
||
| def test_global_length_based_flushing(sentry_init, capture_items, monkeypatch): | ||
| """When the batcher reaches GLOBAL_MAX_BYTES_BEFORE_FLUSH, all buckets will be flushed.""" | ||
| # Limit of 2_000 is just above the size of a bare span. | ||
| monkeypatch.setattr(SpanBatcher, "GLOBAL_MAX_BYTES_BEFORE_FLUSH", 2_000) | ||
|
alexander-alderman-webb marked this conversation as resolved.
alexander-alderman-webb marked this conversation as resolved.
|
||
| # set the time-based flush limit to something huge so that it doesn't | ||
| # interfere | ||
| monkeypatch.setattr(SpanBatcher, "FLUSH_WAIT_TIME", 100000) | ||
|
|
||
| sentry_init( | ||
| traces_sample_rate=1.0, | ||
| trace_lifecycle="stream", | ||
| ) | ||
|
|
||
| items = capture_items("span") | ||
|
|
||
| with sentry_sdk.traces.start_span(name="span"): | ||
| pass | ||
|
|
||
| sentry_sdk.traces.new_trace() | ||
| with sentry_sdk.traces.start_span(name="span"): | ||
| pass | ||
|
|
||
| time.sleep(0.1) | ||
|
|
||
| assert len(items) == 2 | ||
| assert items[0].payload["name"] == "span" | ||
|
|
||
|
|
||
| def test_total_size_reset_after_length_based_flushing( | ||
| sentry_init, capture_items, monkeypatch | ||
| ): | ||
| """Span is not flushed after a flush reduces the combined span size in bytes below the global limit.""" | ||
| # Limit of 2_000 is just above the size of a bare span. | ||
| monkeypatch.setattr(SpanBatcher, "GLOBAL_MAX_BYTES_BEFORE_FLUSH", 2_000) | ||
| # set the time-based flush limit to something huge so that it doesn't | ||
| # interfere | ||
| monkeypatch.setattr(SpanBatcher, "FLUSH_WAIT_TIME", 100000) | ||
|
|
||
| sentry_init( | ||
|
Check warning on line 379 in tests/tracing/test_span_batcher.py
|
||
|
Comment on lines
+344
to
+379
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Global byte limit tests hardcode span size assumption without dynamic measurement Hardcoding Evidence
Identified by Warden · find-bugs · GYU-MGF |
||
| traces_sample_rate=1.0, | ||
| trace_lifecycle="stream", | ||
| ) | ||
|
|
||
| items = capture_items("span") | ||
|
|
||
| with sentry_sdk.traces.start_span(name="span"): | ||
| pass | ||
|
|
||
| sentry_sdk.traces.new_trace() | ||
| with sentry_sdk.traces.start_span(name="span"): | ||
| pass | ||
|
|
||
| time.sleep(0.1) | ||
|
|
||
| with sentry_sdk.traces.start_span(name="span"): | ||
| pass | ||
|
|
||
| time.sleep(0.1) | ||
|
|
||
| assert len(items) == 2 | ||
| assert items[0].payload["name"] == "span" | ||
|
alexander-alderman-webb marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def test_bucket_recreated_after_flush(sentry_init, capture_envelopes, monkeypatch): | ||
| """Spans for a trace that arrive after that trace's bucket was flushed land in a fresh bucket.""" | ||
| monkeypatch.setattr(SpanBatcher, "MAX_BEFORE_FLUSH", 2) | ||
|
|
@@ -545,6 +608,8 @@ | |
| batcher._span_number = 1 | ||
|
|
||
| batcher._running_size["test-trace-id"] = 42 | ||
| batcher._total_running_size = 42 | ||
|
|
||
| batcher._active.flag = True | ||
| batcher._flush_event.set() | ||
| batcher._running = False | ||
|
|
@@ -559,6 +624,7 @@ | |
| span_number_reset = batcher._span_number == 0 | ||
|
|
||
| running_size_reset = len(batcher._running_size) == 0 | ||
| total_running_size_reset = batcher._total_running_size == 0 | ||
|
|
||
| active_reset = not getattr(batcher._active, "flag", False) | ||
| event_reset = not batcher._flush_event.is_set() | ||
|
|
@@ -572,6 +638,7 @@ | |
| and span_buffer_reset | ||
| and span_number_reset | ||
| and running_size_reset | ||
| and total_running_size_reset | ||
| and active_reset | ||
| and event_reset | ||
| and running_reset | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.