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

Enable foreground tracking for everyone #961

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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 @@ -86,7 +86,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 @@ -13,9 +13,8 @@ describe('foreground context', () => {
beforeEach(() => {
setupBuilder = setup()
.withFakeClock()
.withConfiguration({ isEnabled: () => true })
.beforeBuild(({ configuration }) => {
foregroundContext = startForegroundContexts(configuration)
.beforeBuild(() => {
foregroundContext = startForegroundContexts()
return foregroundContext
})
})
Expand Down
15 changes: 1 addition & 14 deletions packages/rum-core/src/domain/foregroundContexts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {
Configuration,
noop,
addEventListener,
DOM_EVENT,
RelativeTime,
Expand Down Expand Up @@ -28,14 +26,7 @@ export interface ForegroundPeriod {

let foregroundPeriods: ForegroundPeriod[] = []

export function startForegroundContexts(configuration: Configuration): ForegroundContexts {
if (!configuration.isEnabled('track-foreground')) {
return {
getInForeground: () => undefined,
getInForegroundPeriods: () => undefined,
stop: noop,
}
}
export function startForegroundContexts(): ForegroundContexts {
if (document.hasFocus()) {
addNewForegroundPeriod()
}
Expand All @@ -60,10 +51,6 @@ function addNewForegroundPeriod() {
}
const currentForegroundPeriod = foregroundPeriods[foregroundPeriods.length - 1]
if (currentForegroundPeriod !== undefined && currentForegroundPeriod.end === undefined) {
addMonitoringMessage('Previous foreground periods not closed. Continuing current one', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about other messages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, They are not triggered at the moment, I would like to know if we change something and those limit case start to trigger.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By looking at the logs I shared with you earlier, we can see some occurrences for all of them.

inForegroundPeriodsCount: foregroundPeriods.length,
currentForegroundPeriodStart: currentForegroundPeriod.start,
})
return
}
foregroundPeriods.push({
Expand Down