Skip to content

🐛 collect feature flag evaluations before rum start in a map instead of a buffer#4469

Draft
BenoitZugmeyer wants to merge 1 commit intov7from
benoit/pre-start-feature-flags-map
Draft

🐛 collect feature flag evaluations before rum start in a map instead of a buffer#4469
BenoitZugmeyer wants to merge 1 commit intov7from
benoit/pre-start-feature-flags-map

Conversation

@BenoitZugmeyer
Copy link
Copy Markdown
Member

@BenoitZugmeyer BenoitZugmeyer commented Apr 10, 2026

Motivation

When addFeatureFlagEvaluation is called many times before init() or before the SDK
finishes starting, the pre-start buffer (BoundedBuffer) can fill up and silently drop
subsequent calls, including important ones like setUser or setGlobalContext.

Changes

  • Pre-start addFeatureFlagEvaluation calls are now accumulated in a FeatureFlagContext
    (Map<string, ContextValue>) instead of the shared BoundedBuffer. Only the last value
    per key is kept (last write wins).
  • The collected flags are passed to startFeatureFlagContexts and seeded into the first
    view's context when RUM starts. Subsequent views start with an empty context as before.

Trade-off: individual pre-start evaluation calls are no longer replayed in order — only the
final value per key reaches the first view. This is acceptable since overwriting a key before
start is uncommon, and reliability (not silently dropping setUser) takes priority.

Test instructions

  1. Before calling DD_RUM.init(), call DD_RUM.addFeatureFlagEvaluation('my-flag', true)
    many times (more than the buffer limit, i.e. > 10 000 times).
  2. After that, call DD_RUM.setUser({ id: 'test-user' }) and then DD_RUM.init(...).
  3. Verify in the RUM events that the first view includes feature_flags: { "my-flag": true }
    and that the user context (usr.id: "test-user") is correctly set on events.

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

…of a buffer

Previously, `addFeatureFlagEvaluation` calls made before `startRum` were
buffered and replayed after init. This caused the `BoundedBuffer` limit to
be reached when many flags were evaluated early, silently dropping other
buffered calls (e.g. `setUser`).

Instead, pre-start evaluations are now collected into a `FeatureFlagCollection`
(a `Map<string, ContextValue>`) and passed to `startFeatureFlagContexts`,
which seeds the first view's context with it. Subsequent views start with an
empty collection as before. This trades per-evaluation ordering for
reliability.
@cit-pr-commenter-54b7da
Copy link
Copy Markdown

cit-pr-commenter-54b7da bot commented Apr 10, 2026

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 166.91 KiB 166.99 KiB +80 B +0.05%
Rum Profiler 6.09 KiB 6.09 KiB 0 B 0.00%
Rum Recorder 27.10 KiB 27.10 KiB 0 B 0.00%
Logs 53.71 KiB 53.71 KiB 0 B 0.00%
Rum Slim 125.34 KiB 125.42 KiB +78 B +0.06%
Worker 22.99 KiB 22.99 KiB 0 B 0.00%
🚀 CPU Performance
Action Name Base CPU Time (ms) Local CPU Time (ms) 𝚫%
RUM - add global context 0.0062 0.004 -35.48%
RUM - add action 0.0186 0.0129 -30.65%
RUM - add error 0.0184 0.0122 -33.70%
RUM - add timing 0.0043 0.0024 -44.19%
RUM - start view 0.017 0.0119 -30.00%
RUM - start/stop session replay recording 0.0008 0.0007 -12.50%
Logs - log message 0.0266 0.0144 -45.86%
🧠 Memory Performance
Action Name Base Memory Consumption Local Memory Consumption 𝚫
RUM - add global context 33.06 KiB 34.29 KiB +1.23 KiB
RUM - add action 235.46 KiB 243.85 KiB +8.39 KiB
RUM - add timing 36.46 KiB 40.22 KiB +3.76 KiB
RUM - add error 249.30 KiB 238.96 KiB -10.34 KiB
RUM - start/stop session replay recording 32.98 KiB 36.13 KiB +3.15 KiB
RUM - start view 598.66 KiB 616.90 KiB +18.24 KiB
Logs - log message 226.75 KiB 236.48 KiB +9.73 KiB

🔗 RealWorld

@datadog-datadog-prod-us1-2
Copy link
Copy Markdown

datadog-datadog-prod-us1-2 bot commented Apr 10, 2026

⚠️ Tests

Fix all issues with BitsAI or with Cursor

⚠️ Other Violations

🧪 1 Test failed

serializeNodeAsChange for snapshotted documents for a simple document when the <html> element's privacy level is HIDDEN matches the snapshot from Safari 14.1.2 (Mac OS 10.15.7)   View in Datadog   (Fix with Cursor)
Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) in node_modules/jasmine-core/lib/jasmine-core/jasmine.js (line 8638)
<Jasmine>

ℹ️ Info

No other issues found (see more)

❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 84.62%
Overall Coverage: 78.16% (-0.01%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: bb7dcdf | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or 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