Skip to content

RUM-17613: timeseries [4/5] Flush the batch in background - #3719

Merged
satween merged 2 commits into
feature/timeseriesfrom
tvaleev/feature/RUM-17613-3b-background-suspend
Aug 18, 2026
Merged

RUM-17613: timeseries [4/5] Flush the batch in background#3719
satween merged 2 commits into
feature/timeseriesfrom
tvaleev/feature/RUM-17613-3b-background-suspend

Conversation

@satween

@satween satween commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes timeseries not being sent when the app goes to background with a partially filled batch.

Sampling used to keep running in background (unless collectInBackground was off) and the buffer was only written on session stop, so points collected before a backgrounding could stay unsent for the rest of the session. Now, when the active view leaves the foreground, the collector suspends the sampling chain and flushes the buffers, attributing the batch to the last foreground context — a background flush has no view of its own to attribute to.

The suspension is delayed by 200 ms to match ActivityViewTrackingStrategy.STOP_VIEW_DELAY_MS: an Activity-to-Activity transition leaves no active view for a moment and must not be mistaken for a backgrounding. If the app returns to the foreground within that window, collection simply continues. Sampling state carries a generation counter so a suspension pending on an older generation cannot stop a chain that has since been resumed.

TimeseriesConfiguration.collectInBackground is dropped: background suspension is now unconditional, so the flag no longer has a meaning.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

Ref: RUM-17613

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Aug 14, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🔄 Datadog retried 1 test - 1 passed on retry View in Datadog

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 72.82% (+0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: febc38d | Docs | View more details | Give us feedback!

@satween
satween force-pushed the tvaleev/feature/RUM-17613-3b-background-suspend branch from 40a19e5 to 57ac354 Compare August 17, 2026 08:55

satween commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

@satween
satween force-pushed the tvaleev/feature/RUM-17613-3b-background-suspend branch 2 times, most recently from 8f84420 to a689c33 Compare August 17, 2026 10:45
@satween
satween marked this pull request as ready for review August 17, 2026 10:55
@satween
satween requested review from a team as code owners August 17, 2026 10:55
@satween
satween force-pushed the tvaleev/feature/RUM-17613-3b-background-suspend branch from a689c33 to 369a5ee Compare August 17, 2026 12:05

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 369a5eee5a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Base automatically changed from tvaleev/feature/RUM-17613-3-background-flush to feature/timeseries August 17, 2026 12:46
Sampling kept running while the app sat in background, and the buffered batch
was only written on session stop, so points collected before a backgrounding
could stay unsent for the rest of the session.

The collector now suspends the sampling chain when the active view leaves the
foreground and flushes the buffers at that point, attributing the batch to the
last foreground context. The suspension is delayed by 200 ms to match
ActivityViewTrackingStrategy.STOP_VIEW_DELAY_MS, so an Activity-to-Activity
transition is not mistaken for a backgrounding. Sampling state carries a
generation counter so a suspension pending on an older generation cannot stop a
chain that has since been resumed.

Drops TimeseriesConfiguration.collectInBackground: background suspension is now
unconditional, so the flag no longer has a meaning.

Ref: RUM-17613
@satween
satween force-pushed the tvaleev/feature/RUM-17613-3b-background-suspend branch from 369a5ee to 2f61d4f Compare August 17, 2026 12:46
Comment on lines 85 to +55
val isEnterForeground = !oldViewType.isForeground && newViewType.isForeground
val isLeaveForeground = oldViewType.isForeground && !newViewType.isForeground

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe it is worth to add a callback to the ProcessLifecycleMonitor? Although this approach probably also works.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, but as long as we catching the rumContext which is required to build proper timeseries batch event - I prefer to keep the existing logic for now. Plus it allows to catch a specific scenario, when app is not fully in foreground, but starting (APPLICATION_LAUNCH) which could be very important for the timeseries

The pending suspend read lastForegroundRumContext at fire time, so a
foreground re-entry landing between stopGeneration() and the flush made it
attribute the previous view's batch to the new view. Snapshot the context
when the stop is scheduled instead.
@satween
satween requested a review from 0xnm August 18, 2026 10:54
@satween
satween merged commit d3594b5 into feature/timeseries Aug 18, 2026
23 checks passed
@satween
satween deleted the tvaleev/feature/RUM-17613-3b-background-suspend branch August 18, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants