relay icon indicating copy to clipboard operation
relay copied to clipboard

Fix integer overflow in times_seen field

Open trillville opened this issue 3 months ago • 1 comments

Fixes an integer out of range error in the times_seen column of sentry_groupedmessage.

This error occurs when client SDKs send events with extremely low sample_rate values. The Sentry backend calculates times_seen by inverting this rate (1 / sample_rate), which can result in a value exceeding PostgreSQL's integer field limit (2,147,483,647).

This PR introduces a validation function in Relay (validate_sample_rate_for_times_seen) that caps the effective sample_rate if its inverse would lead to an integer overflow. This validation is applied during event normalization and to Dynamic Sampling Contexts.

This prevents database errors by ensuring times_seen values remain within PostgreSQL's integer bounds, with warnings logged when a sample rate is capped.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.


Open in Cursor Open in Web

trillville avatar Sep 26 '25 01:09 trillville

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch. Learn more about Cursor Agents

cursor[bot] avatar Sep 26 '25 01:09 cursor[bot]