File tree 1 file changed +18
-1
lines changed
1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -19,11 +19,17 @@ const ERRORS_TO_DISCARD = [
19
19
20
20
const REPORTED_ERRORS_KEY = 'sentry:reportedErrors' ;
21
21
const TIMESTAMP_KEY = 'sentry:errorReportingInit' ;
22
- const ONE_DAY_MS = 60 * 60 * 24 * 1000 ;
22
+ const ONE_DAY_MS = 24 * 60 * 60 * 1000 ;
23
+ const HALF_HOUR_MS = 0.5 * 60 * 60 * 1000 ;
23
24
24
25
export function preprocessSentryError ( event : Event ) {
25
26
const message = getMessage ( event ) ;
26
27
28
+ // Check if it's rate limited to avoid sending the same error over and over
29
+ if ( isRateLimited ( message || 'empty' ) ) {
30
+ return null ;
31
+ }
32
+
27
33
// If we don't know about this particular type of event then just pass it along
28
34
if ( ! message ) {
29
35
return event ;
@@ -73,6 +79,17 @@ function isLocalStorageAvailable(): boolean {
73
79
}
74
80
}
75
81
82
+ // https://github.com/getsentry/sentry-javascript/issues/435
83
+ const rateLimiter : Record < string , number > = { } ;
84
+ function isRateLimited ( message : string ) {
85
+ if ( rateLimiter [ message ] && rateLimiter [ message ] > Date . now ( ) ) {
86
+ return true ;
87
+ }
88
+
89
+ rateLimiter [ message ] = Date . now ( ) + HALF_HOUR_MS ;
90
+ return false ;
91
+ }
92
+
76
93
// Extract a stable event error message out of the Sentry event object
77
94
function getMessage ( event : Event ) {
78
95
if ( event . message ) {
You can’t perform that action at this time.
0 commit comments