-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 [RUMF-1421] keep updating the view event counters after view end
- Loading branch information
1 parent
399c85c
commit 060a6dd
Showing
3 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 21 additions & 1 deletion
22
packages/rum-core/src/domain/rumEventsCollection/view/trackViewEventCounts.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,32 @@ | ||
import { ONE_MINUTE } from '@datadog/browser-core' | ||
import type { LifeCycle } from '../../lifeCycle' | ||
import { trackEventCounts } from '../../trackEventCounts' | ||
|
||
// Arbitrary delay for stopping event counting after the view ends. Ideally, we would not stop and | ||
// keep counting events until the end of the session. But this might have a small performance impact | ||
// if there are many many views: we would need to go through each event to see if the related view | ||
// matches. So let's have a fairly short delay to avoid impacting performances too much. | ||
// | ||
// In the future, we could have views stored in a data structure similar to ContextHistory. Whenever | ||
// a child event is collected, we could look into this history to find the matching view and | ||
// increase the associated and increase its counter. Having a centralized data structure for it | ||
// would allow us to look for views more efficiently. | ||
// | ||
// For now, having a small cleanup delay will already improve the situation in most cases. | ||
|
||
export const KEEP_TRACKING_EVENT_COUNTS_AFTER_VIEW_DELAY = 5 * ONE_MINUTE | ||
|
||
export function trackViewEventCounts(lifeCycle: LifeCycle, viewId: string, onChange: () => void) { | ||
const { stop, eventCounts } = trackEventCounts({ | ||
lifeCycle, | ||
isChildEvent: (event) => event.view.id === viewId, | ||
onChange, | ||
}) | ||
|
||
return { stop, eventCounts } | ||
return { | ||
scheduleStop: () => { | ||
setTimeout(stop, KEEP_TRACKING_EVENT_COUNTS_AFTER_VIEW_DELAY) | ||
}, | ||
eventCounts, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters