Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove focus feature flag #1053

Merged
merged 3 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/rum-core/src/boot/startRum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function startRumEventCollection(
getCommonContext: () => CommonContext
) {
const parentContexts = startParentContexts(lifeCycle, session)
const foregroundContexts = startForegroundContexts(configuration)
const foregroundContexts = startForegroundContexts()
const batch = startRumBatch(configuration, lifeCycle)

startRumAssembly(applicationId, configuration, lifeCycle, session, parentContexts, getCommonContext)
Expand Down
5 changes: 2 additions & 3 deletions packages/rum-core/src/domain/foregroundContexts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ describe('foreground context', () => {
beforeEach(() => {
setupBuilder = setup()
.withFakeClock()
.withConfiguration({ isEnabled: () => true })
.beforeBuild(({ configuration }) => {
foregroundContext = startForegroundContexts(configuration)
.beforeBuild(() => {
foregroundContext = startForegroundContexts()
return foregroundContext
})
})
Expand Down
40 changes: 1 addition & 39 deletions packages/rum-core/src/domain/foregroundContexts.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import {
Configuration,
noop,
addEventListener,
DOM_EVENT,
RelativeTime,
elapsed,
relativeNow,
Duration,
addMonitoringMessage,
toServerDuration,
} from '@datadog/browser-core'
import { InForegroundPeriod } from '../rawRumEvent.types'
Expand All @@ -16,9 +13,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 All @@ -33,15 +27,7 @@ export interface ForegroundPeriod {

let foregroundPeriods: ForegroundPeriod[] = []

export function startForegroundContexts(configuration: Configuration): ForegroundContexts {
if (!configuration.isEnabled('track-foreground')) {
return {
isInForegroundAt: () => undefined,
selectInForegroundPeriodsFor: () => undefined,
stop: noop,
}
}

export function startForegroundContexts(): ForegroundContexts {
if (document.hasFocus()) {
addNewForegroundPeriod()
}
Expand All @@ -61,22 +47,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 +61,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