Skip to content

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

Draft
satween wants to merge 1 commit into
tvaleev/feature/RUM-17613-3-background-flushfrom
tvaleev/feature/RUM-17613-3b-background-suspend
Draft

RUM-17613: timeseries [4/5] Flush the batch in background#3719
satween wants to merge 1 commit into
tvaleev/feature/RUM-17613-3-background-flushfrom
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

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
@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 auto-retried 2 jobs - 2 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: 40a19e5 | Docs | Datadog PR Page | Give us feedback!

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.

1 participant