2026-07-20 16:05:17 +00:00
// Module ID: 1140
2026-07-23 10:11:24 +00:00
// Function ID: 12996
2026-07-20 16:05:17 +00:00
// Name: stallTrackingIntegration
2026-07-23 10:11:24 +00:00
// Dependencies: [57, 27, 794, 1098, 1132, 1135]
2026-07-20 16:05:17 +00:00
// Exports: stallTrackingIntegration
// Module 1140 (stallTrackingIntegration)
2026-07-23 10:11:24 +00:00
import _slicedToArray from "_slicedToArray" ;
import { AppState } from "get ActivityIndicator" ;
const require = arg1 ;
2026-07-20 16:05:17 +00:00
export const stallTrackingIntegration = function stallTrackingIntegration ( ) {
if ( arguments . length > 0 ) {
if ( undefined !== arguments [ 0 ] ) {
const first = arguments [ 0 ] ;
}
const minimumStallThresholdMs = { } . minimumStallThresholdMs ;
let num = 50 ;
if ( undefined !== minimumStallThresholdMs ) {
num = minimumStallThresholdMs ;
}
const _Map = Map ;
const map = new Map ( ) ;
let obj = {
2026-07-23 10:11:24 +00:00
isTracking : false ,
timeout : null ,
isBackground : false ,
lastIntervalMs : 0 ,
totalStallTime : 0 ,
stallCount : 0 ,
2026-07-20 16:05:17 +00:00
backgroundEventListener ( arg0 ) {
if ( "active" === arg0 ) {
obj . isBackground = false ;
if ( null != obj . timeout ) {
2026-07-23 10:11:24 +00:00
obj = 2 ( map [ 2 ] ) ;
2026-07-20 16:05:17 +00:00
obj . lastIntervalMs = 1000 * obj . timestampInSeconds ( ) ;
obj . iteration ( ) ;
}
} else {
obj . isBackground = true ;
if ( null !== obj . timeout ) {
const _clearTimeout = clearTimeout ;
clearTimeout ( obj . timeout ) ;
}
}
} ,
iteration ( ) {
let num ;
let tmp28 ;
let tmp29 ;
let obj = num ( map [ 2 ] ) ;
const result = 1000 * obj . timestampInSeconds ( ) ;
const diff = result - obj . lastIntervalMs ;
if ( diff >= 50 + num ) {
const diff1 = diff - 50 ;
obj . stallCount = obj . stallCount + 1 ;
obj . totalStallTime = obj . totalStallTime + diff1 ;
const entries = map . entries ( ) ;
const tmp23 = entries [ Symbol . iterator ] ( ) ;
while ( tmp23 !== undefined ) {
let tmp26 = obj ;
let tmp27 = obj ( tmp3 , 2 ) ;
[ tmp28 , tmp29 ] = tmp27 ;
let longestStallTime = tmp29 . longestStallTime ;
num = 0 ;
let tmp30 = tmp29 ;
if ( null !== longestStallTime ) {
let tmp5 = longestStallTime ;
num = 0 ;
if ( undefined !== tmp31 ) {
num = longestStallTime ;
}
}
let tmp6 = diff1 ;
let tmp8 = map ;
let tmp9 = tmp28 ;
let _Object = Object ;
let _Object2 = Object ;
let tmp10 = tmp29 ;
let bound = Math . max ( num , tmp17 ) ;
obj = { longestStallTime : bound } ;
let result1 = map . set ( tmp28 , Object . assign ( Object . assign ( { } , tmp30 ) , obj ) ) ;
2026-07-23 10:11:24 +00:00
continue ;
2026-07-20 16:05:17 +00:00
}
2026-07-23 10:11:24 +00:00
tmp17 = diff1 ;
2026-07-20 16:05:17 +00:00
}
obj . lastIntervalMs = result ;
let isTracking = obj . isTracking ;
if ( isTracking ) {
isTracking = ! obj . isBackground ;
}
if ( isTracking ) {
const _setTimeout = setTimeout ;
obj . timeout = setTimeout ( obj . iteration , 50 ) ;
}
}
} ;
2026-07-23 10:11:24 +00:00
function _onSpanStart ( outer1 _0 ) {
2026-07-20 16:05:17 +00:00
let obj = num ( map [ 3 ] ) ;
2026-07-23 10:11:24 +00:00
if ( obj . isRootSpan ( outer1 _0 ) ) {
if ( map . has ( outer1 _0 ) ) {
2026-07-20 16:05:17 +00:00
const debug = num ( map [ 2 ] ) . debug ;
debug . error ( "[StallTracking] Tried to start stall tracking on a transaction already being tracked. Measurements might be lost." ) ;
} else {
_startTracking ( ) ;
2026-07-23 10:11:24 +00:00
obj = { longestStallTime : 0 , atTimestamp : null , atStart : _getCurrentStats ( outer1 _0 ) } ;
const result = map . set ( outer1 _0 , obj ) ;
2026-07-20 16:05:17 +00:00
_flushLeakedTransactions ( ) ;
}
}
}
2026-07-23 10:11:24 +00:00
function _onSpanEnd ( outer1 _0 ) {
if ( obj . isRootSpan ( outer1 _0 ) ) {
const value = map . get ( outer1 _0 ) ;
2026-07-20 16:05:17 +00:00
const obj2 = 2 ( map [ 2 ] ) ;
if ( value ) {
2026-07-23 10:11:24 +00:00
const timestamp = obj2 . spanToJSON ( outer1 _0 ) . timestamp ;
2026-07-20 16:05:17 +00:00
if ( tmp4Result . isNearToNow ( timestamp ) ) {
2026-07-23 10:11:24 +00:00
let stats = _getCurrentStats ( outer1 _0 ) ;
2026-07-20 16:05:17 +00:00
} else {
2026-07-23 10:11:24 +00:00
const latestChildSpanEndTimestamp = num ( map [ 4 ] ) . getLatestChildSpanEndTimestamp ( outer1 _0 ) ;
2026-07-20 16:05:17 +00:00
if ( latestChildSpanEndTimestamp !== timestamp ) {
const debug2 = num ( map [ 2 ] ) . debug ;
debug2 . log ( "[StallTracking] Stall measurements not added due to a custom `endTimestamp` (root end is not equal to the latest child span end)." ) ;
}
if ( ! value . atTimestamp ) {
const debug3 = num ( map [ 2 ] ) . debug ;
debug3 . log ( "[StallTracking] Stall measurements not added due to `endTimestamp` not being close to now. And no previous stats from child end were found." ) ;
}
if ( tmp20 ) {
stats = value . atTimestamp . stats ;
}
const obj4 = num ( map [ 4 ] ) ;
2026-07-23 10:11:24 +00:00
tmp20 = latestChildSpanEndTimestamp === timestamp && value . atTimestamp ;
2026-07-20 16:05:17 +00:00
}
2026-07-23 10:11:24 +00:00
map . delete ( outer1 _0 ) ;
2026-07-20 16:05:17 +00:00
_shouldStopTracking ( ) ;
if ( stats ) {
const obj5 = num ( map [ 4 ] ) ;
2026-07-23 10:11:24 +00:00
obj5 . setSpanMeasurement ( outer1 _0 , num ( map [ 5 ] ) . STALL _COUNT , stats . stall _count . value - value . atStart . stall _count . value , value . atStart . stall _count . unit ) ;
2026-07-20 16:05:17 +00:00
const obj6 = num ( map [ 4 ] ) ;
2026-07-23 10:11:24 +00:00
obj6 . setSpanMeasurement ( outer1 _0 , num ( map [ 5 ] ) . STALL _TOTAL _TIME , stats . stall _total _time . value - value . atStart . stall _total _time . value , value . atStart . stall _total _time . unit ) ;
2026-07-20 16:05:17 +00:00
const obj7 = num ( map [ 4 ] ) ;
2026-07-23 10:11:24 +00:00
obj7 . setSpanMeasurement ( outer1 _0 , num ( map [ 5 ] ) . STALL _LONGEST _TIME , stats . stall _longest _time . value , stats . stall _longest _time . unit ) ;
2026-07-20 16:05:17 +00:00
} else if ( undefined !== timestamp ) {
const debug4 = num ( map [ 2 ] ) . debug ;
debug4 . log ( "[StallTracking] Stall measurements not added due to `endTimestamp` not being close to now." , "endTimestamp" , timestamp , "now" , num ( map [ 2 ] ) . timestampInSeconds ( ) ) ;
const obj8 = num ( map [ 2 ] ) ;
}
} else {
const debug = obj2 . debug ;
debug . log ( "[StallTracking] Stall measurements were not added to transaction due to exceeding the max count." ) ;
2026-07-23 10:11:24 +00:00
map . delete ( outer1 _0 ) ;
2026-07-20 16:05:17 +00:00
_shouldStopTracking ( ) ;
}
const tmp5 = map ;
} else {
2026-07-23 10:11:24 +00:00
return _onChildSpanEnd ( outer1 _0 ) ;
2026-07-20 16:05:17 +00:00
}
2026-07-23 10:11:24 +00:00
obj = num ( map [ 3 ] ) ;
2026-07-20 16:05:17 +00:00
}
2026-07-23 10:11:24 +00:00
function _onChildSpanEnd ( outer1 _0 ) {
const rootSpan = num ( map [ 2 ] ) . getRootSpan ( outer1 _0 ) ;
2026-07-20 16:05:17 +00:00
const obj = num ( map [ 2 ] ) ;
2026-07-23 10:11:24 +00:00
const timestamp = num ( map [ 2 ] ) . spanToJSON ( outer1 _0 ) . timestamp ;
2026-07-20 16:05:17 +00:00
if ( timestamp ) {
_markSpanFinish ( rootSpan , timestamp ) ;
}
}
function _markSpanFinish ( rootSpan , timestamp ) {
const value = map . get ( rootSpan ) ;
if ( value ) {
const _Math = Math ;
let obj = num ( map [ 2 ] ) ;
if ( Math . abs ( obj . timestampInSeconds ( ) - timestamp ) > 0.02 ) {
const debug = num ( map [ 2 ] ) . debug ;
debug . log ( "[StallTracking] Span end not logged due to end timestamp being outside the margin of error from now." ) ;
if ( tmp12 ) {
const _Object3 = Object ;
const _Object4 = Object ;
obj = { atTimestamp : null } ;
const result = map . set ( rootSpan , Object . assign ( Object . assign ( { } , value ) , obj ) ) ;
}
2026-07-23 10:11:24 +00:00
tmp12 = value . atTimestamp && value . atTimestamp . timestamp < timestamp ;
2026-07-20 16:05:17 +00:00
} else {
const _Object = Object ;
const _Object2 = Object ;
obj = { } ;
const obj1 = { timestamp } ;
const merged = Object . assign ( { } , value ) ;
obj1 . stats = _getCurrentStats ( rootSpan ) ;
obj . atTimestamp = obj1 ;
const result1 = map . set ( rootSpan , Object . assign ( merged , obj ) ) ;
}
}
}
function _getCurrentStats ( rootSpan ) {
2026-07-23 10:11:24 +00:00
obj = { stall _count : obj , stall _total _time : obj } ;
2026-07-20 16:05:17 +00:00
obj = { value : obj . stallCount , unit : "none" } ;
obj = { value : obj . totalStallTime , unit : "millisecond" } ;
const obj1 = { } ;
const value = map . get ( rootSpan ) ;
let longestStallTime ;
if ( null !== value ) {
if ( undefined !== value ) {
longestStallTime = value . longestStallTime ;
}
}
let num = 0 ;
if ( null !== longestStallTime ) {
num = 0 ;
if ( undefined !== longestStallTime ) {
num = longestStallTime ;
}
}
obj1 . value = num ;
obj1 . unit = "millisecond" ;
obj . stall _longest _time = obj1 ;
return obj ;
}
function _startTracking ( ) {
if ( ! obj . isTracking ) {
obj . isTracking = true ;
const _Math = Math ;
2026-07-23 10:11:24 +00:00
obj = 2 ( map [ 2 ] ) ;
2026-07-20 16:05:17 +00:00
obj . lastIntervalMs = Math . floor ( 1000 * obj . timestampInSeconds ( ) ) ;
obj . iteration ( ) ;
}
}
function _shouldStopTracking ( ) {
if ( 0 === map . size ) {
obj . isTracking = false ;
if ( null !== obj . timeout ) {
const _clearTimeout = clearTimeout ;
clearTimeout ( obj . timeout ) ;
obj . timeout = null ;
}
_reset ( ) ;
}
}
function _reset ( ) {
obj . stallCount = 0 ;
obj . totalStallTime = 0 ;
obj . lastIntervalMs = 0 ;
map . clear ( ) ;
}
function _flushLeakedTransactions ( ) {
if ( map . size > 10 ) {
let num = 0 ;
const diff = map . size - 10 ;
const keys = map . keys ( ) ;
const iter = keys [ Symbol . iterator ] ( ) ;
while ( iter !== undefined ) {
let tmp9 = num ;
let tmp10 = diff ;
if ( num >= diff ) {
iter . return ( ) ;
2026-07-23 10:11:24 +00:00
break ;
2026-07-20 16:05:17 +00:00
} else {
let tmp11 = num ;
num = num + 1 ;
let tmp12 = map ;
let tmp13 = nextResult ;
let deleteResult = map . delete ( tmp8 ) ;
2026-07-23 10:11:24 +00:00
continue ;
2026-07-20 16:05:17 +00:00
}
break ;
}
2026-07-23 10:11:24 +00:00
nextResult = iter . next ( ) ;
2026-07-20 16:05:17 +00:00
}
}
let isAvailable ;
if ( null != _onSpanStart ) {
isAvailable = _onSpanStart . isAvailable ;
}
if ( isAvailable ) {
const listener = _onSpanStart . addEventListener ( "change" , obj . backgroundEventListener ) ;
}
obj = {
name : "StallTracking" ,
setup ( on ) {
on . on ( "spanStart" , _onSpanStart ) ;
on . on ( "spanEnd" , _onSpanEnd ) ;
}
} ;
obj . _internalState = obj ;
return obj ;
}
} ;