Skip to content

Commit

Permalink
fix(perf-issues): Large payload detector comparison types (#79292)
Browse files Browse the repository at this point in the history
Fixes SENTRY-FOR-SENTRY-1WGS

Sometimes the `encoded_body_size` is stored as a string, so it will need
to be converted to an int or the comparison will result in an error

---------

Co-authored-by: Lyn Nagara <[email protected]>
  • Loading branch information
0Calories and lynnagara authored Oct 17, 2024
1 parent 28afdb8 commit 02638a8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def visit_span(self, span: Span) -> None:
return

payload_size_threshold = self.settings.get("payload_size_threshold")

if isinstance(encoded_body_size, str):
encoded_body_size = int(encoded_body_size)

if encoded_body_size > payload_size_threshold:
self._store_performance_problem(span)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_detects_large_http_payload_issue(self):
"http.response_content_length": 50_000_000,
"http.decoded_response_content_length": 50_000_000,
},
)
),
]

event = create_event(spans)
Expand Down Expand Up @@ -250,3 +250,39 @@ def test_does_not_trigger_detection_for_http_span_lower_than_100_ms_duration(sel
]
event = create_event(spans)
assert self.find_problems(event) == []

def test_handles_string_payload_size_threshold(self):

spans = [
create_span(
"http.client",
1000,
"GET /api/0/organizations/endpoint1",
"hash2",
data={
"http.response_transfer_size": "50_000_000",
"http.response_content_length": "50_000_000",
"http.decoded_response_content_length": "50_000_000",
},
),
]

event = create_event(spans)
assert self.find_problems(event) == [
PerformanceProblem(
fingerprint="1-1015-5e5543895c0f1f12c2d468da8c7f2d9e4dca81dc",
op="http",
desc="GET /api/0/organizations/endpoint1",
type=PerformanceLargeHTTPPayloadGroupType,
parent_span_ids=None,
cause_span_ids=[],
offender_span_ids=["bbbbbbbbbbbbbbbb"],
evidence_data={
"parent_span_ids": [],
"cause_span_ids": [],
"offender_span_ids": ["bbbbbbbbbbbbbbbb"],
"op": "http",
},
evidence_display=[],
)
]

0 comments on commit 02638a8

Please sign in to comment.