Skip to content

Commit

Permalink
Remove monitoring for foregroundContext
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibautGeriz committed Sep 15, 2021
1 parent 7b7baf9 commit 844bbcb
Showing 1 changed file with 0 additions and 28 deletions.
28 changes: 0 additions & 28 deletions packages/rum-core/src/domain/foregroundContexts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
elapsed,
relativeNow,
Duration,
addMonitoringMessage,
toServerDuration,
} from '@datadog/browser-core'
import { InForegroundPeriod } from '../rawRumEvent.types'
Expand All @@ -16,9 +15,6 @@ import { InForegroundPeriod } from '../rawRumEvent.types'
export const MAX_NUMBER_OF_SELECTABLE_FOREGROUND_PERIODS = 500
// Arbitrary value to cap number of element mostly for memory consumption in the browser
export const MAX_NUMBER_OF_STORED_FOREGROUND_PERIODS = 2500
// ignore duplicate focus & blur events if coming in the right after the previous one
// chrome bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1237904
const MAX_TIME_TO_IGNORE_DUPLICATE = 10 as RelativeTime

export interface ForegroundContexts {
isInForegroundAt: (startTime: RelativeTime) => boolean | undefined
Expand Down Expand Up @@ -61,22 +57,11 @@ export function startForegroundContexts(configuration: Configuration): Foregroun

export function addNewForegroundPeriod() {
if (foregroundPeriods.length > MAX_NUMBER_OF_STORED_FOREGROUND_PERIODS) {
addMonitoringMessage('Reached maximum of foreground time')
return
}
const currentForegroundPeriod = foregroundPeriods[foregroundPeriods.length - 1]
const now = relativeNow()
if (currentForegroundPeriod !== undefined && currentForegroundPeriod.end === undefined) {
if (now - currentForegroundPeriod.start > MAX_TIME_TO_IGNORE_DUPLICATE) {
addMonitoringMessage('Previous foreground periods not closed. Continuing current one', {
foregroundPeriods: {
count: foregroundPeriods.length,
currentStart: currentForegroundPeriod.start,
now,
diff: now - currentForegroundPeriod.start,
},
})
}
return
}
foregroundPeriods.push({
Expand All @@ -86,24 +71,11 @@ export function addNewForegroundPeriod() {

export function closeForegroundPeriod() {
if (foregroundPeriods.length === 0) {
addMonitoringMessage('No foreground period')
return
}
const currentForegroundPeriod = foregroundPeriods[foregroundPeriods.length - 1]
const now = relativeNow()
if (currentForegroundPeriod.end !== undefined) {
if (now - currentForegroundPeriod.end > MAX_TIME_TO_IGNORE_DUPLICATE) {
addMonitoringMessage('Current foreground period already closed', {
foregroundPeriods: {
count: foregroundPeriods.length,
currentStart: currentForegroundPeriod.start,
currentEnd: currentForegroundPeriod.end,
now,
diff: now - currentForegroundPeriod.end,
},
now: relativeNow(),
})
}
return
}
currentForegroundPeriod.end = now
Expand Down

0 comments on commit 844bbcb

Please sign in to comment.