Skip to content

RUM-17613 Flush the pending timeseries batch on backgrounding - #3715

Closed
satween wants to merge 2 commits into
tvaleev/feature/RUM-17613-1-collector-renamefrom
tvaleev/feature/RUM-17613-1b-background-flush
Closed

RUM-17613 Flush the pending timeseries batch on backgrounding#3715
satween wants to merge 2 commits into
tvaleev/feature/RUM-17613-1-collector-renamefrom
tvaleev/feature/RUM-17613-1b-background-flush

Conversation

@satween

@satween satween commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Makes the timeseries collector flush its pending batch when the app leaves the foreground,
instead of dropping whatever was buffered.

The four-state AtomicReference<State> enum is replaced by a generation-counted State
guarded by synchronized. Leaving the foreground schedules a deferred suspension
(SUSPEND_DELAY_MS = 200) which, if the app is still not in the foreground when it fires,
deactivates the current generation and flushes every pipeline. Returning to the foreground
cancels a suspension that has not fired yet, or starts a fresh sampling generation if it already
did. Sampling now only runs on a foreground view, so onSessionStart needs to know which view
the session begins on — TimeseriesCollector.Factory.create takes a viewType, supplied by
RumSessionScope from the active RUM context.

Because sampling is unconditionally suspended outside the foreground,
TimeseriesConfiguration.Builder.collectInBackground no longer has anything to switch and is
removed together with its tests.

Motivation

Without this, a batch that is still filling when the user backgrounds the app is silently lost:
sampling was simply paused, and the buffer was only drained on session stop. The 200 ms debounce
mirrors ActivityViewTrackingStrategy.STOP_VIEW_DELAY_MS, which guards the same race — an
Activity-to-Activity transition briefly leaves no active view when the tracking strategy stops
the view on pause rather than on stop, and that must not be mistaken for backgrounding.

Additional Notes

The new State has no terminal STOPPED, so onSessionStart after onSessionStop would
restart sampling. That invariant is now the caller's: RumSessionScope.stopTimeseries() swaps in
a NoOpTimeseriesCollector, and a fresh collector is built per session. The test that asserted
the old terminal behaviour is dropped for that reason.

The three AtomicReference<DefaultTimeseriesCollector.State> detekt safe-call entries go away
with the AtomicReference.

api/apiSurface and api/dd-sdk-android-rum.api are unchanged — every removed member was
internal (verified by re-running generateApiSurface + apiDump).

Instrumented tests are intentionally not part of this PR; they arrive with the last PR of the
stack.

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

Rename the internal Timeseries interface to TimeseriesCollector and rename its
implementations to DefaultTimeseriesCollector and
DefaultTimeseriesCollectorFactory, propagating the new names through
RumFeature, the RUM scope tree and the tests. No behaviour change.

Ref: RUM-17613
Replace the collector's four-state enum with a generation-counted state and
schedule a 200 ms deferred suspension when the app leaves the foreground, so the
buffered batch is written instead of dropped. Sampling only runs on a foreground
view, which makes the collectInBackground switch obsolete.

Ref: RUM-17613

satween commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@datadog-datadog-prod-us1

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

Copy link
Copy Markdown

Pipelines  Tests

⚠️ Warnings

🚦 8 Pipeline jobs failed

CodeQL | Analyze (java)   View in Datadog   GitHub Actions

See error Ref 'refs/heads/graphite-base/3712' not found in this repository, causing CodeQL job configuration error.

DataDog/dd-sdk-android | analysis:android-lint   View in Datadog   GitLab

DataDog/dd-sdk-android | analysis:detekt   View in Datadog   GitLab

View all 8 failed jobs.

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

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

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 2833c04 | Docs | Datadog PR Page | Give us feedback!

@satween
satween force-pushed the tvaleev/feature/RUM-17613-1-collector-rename branch from a90a51b to 71b5db2 Compare August 14, 2026 14:32
@satween

satween commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

Superseded: the background-collection fix now sits after the schema PR in the stack and carries the full RumContext migration. Replaced by #3717 (branch renamed to tvaleev/feature/RUM-17613-3-background-flush).

@satween satween closed this Aug 14, 2026
@satween
satween deleted the tvaleev/feature/RUM-17613-1b-background-flush branch August 14, 2026 14:34
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