1
- import { useEffect } from 'react' ;
1
+ import { useEffect , useRef } from 'react' ;
2
2
import * as Sentry from '@sentry/react' ;
3
3
4
4
import { defined } from 'sentry/utils' ;
@@ -416,9 +416,30 @@ export function useLogAnalytics({
416
416
const tableError = logsTableResult . error ?. message ?? '' ;
417
417
const query_status = tableError ? 'error' : 'success' ;
418
418
const autorefreshEnabled = useLogsAutoRefreshEnabled ( ) ;
419
+ const autorefreshBox = useRef ( autorefreshEnabled ) ; // Boxed to avoid useEffect firing analytics on changes.
420
+ const resultLengthBox = useRef ( logsTableResult . data ?. length || 0 ) ; // Boxed to avoid useEffect firing analytics on changes.
421
+ const isDisablingAutorefresh = useRef ( false ) ;
422
+
423
+ autorefreshBox . current = autorefreshEnabled ;
424
+ resultLengthBox . current = logsTableResult . data ?. length || 0 ;
419
425
420
426
useEffect ( ( ) => {
421
- if ( logsTableResult . isPending || isLoadingSubscriptionDetails || autorefreshEnabled ) {
427
+ if ( ! autorefreshEnabled ) {
428
+ isDisablingAutorefresh . current = true ;
429
+ }
430
+ } , [ autorefreshEnabled ] ) ;
431
+
432
+ useEffect ( ( ) => {
433
+ if ( isDisablingAutorefresh . current ) {
434
+ isDisablingAutorefresh . current = false ;
435
+ return ;
436
+ }
437
+
438
+ if (
439
+ logsTableResult . isPending ||
440
+ isLoadingSubscriptionDetails ||
441
+ autorefreshBox . current
442
+ ) {
422
443
// Auto-refresh causes constant metadata events, so we don't want to track them.
423
444
return ;
424
445
}
@@ -430,7 +451,7 @@ export function useLogAnalytics({
430
451
columns,
431
452
columns_count : columns . length ,
432
453
query_status,
433
- table_result_length : logsTableResult . data ?. length || 0 ,
454
+ table_result_length : resultLengthBox . current ,
434
455
table_result_missing_root : 0 ,
435
456
user_queries : search . formatString ( ) ,
436
457
user_queries_count : search . tokens . length ,
@@ -445,7 +466,7 @@ export function useLogAnalytics({
445
466
query: ${ query }
446
467
fields: ${ fields }
447
468
query_status: ${ query_status }
448
- result_length: ${ String ( logsTableResult . data ?. length || 0 ) }
469
+ result_length: ${ String ( resultLengthBox . current ) }
449
470
user_queries: ${ search . formatString ( ) }
450
471
user_queries_count: ${ String ( search . tokens . length ) }
451
472
has_exceeded_performance_usage_limit: ${ String ( hasExceededPerformanceUsageLimit ) }
@@ -463,9 +484,7 @@ export function useLogAnalytics({
463
484
query_status ,
464
485
page_source ,
465
486
logsTableResult . isPending ,
466
- logsTableResult . data ?. length ,
467
487
search ,
468
- autorefreshEnabled ,
469
488
] ) ;
470
489
}
471
490
0 commit comments