Skip to content

♻️ [RUM-19970] Give RUM plugins a call queue, the consent state and the session manager - #5295

Draft
mormubis wants to merge 5 commits into
mainfrom
adlrb/rum-plugin-call-queue
Draft

mormubis wants to merge 5 commits into
mainfrom
adlrb/rum-plugin-call-queue

Conversation

@mormubis

@mormubis mormubis commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

The Logs plugin should build on RUM's state instead of starting its own copy. Today plugins can't do that. onRumStart only gives them addEvent and addError, and calls a plugin makes before init() have nowhere to go.

This PR adds what the plugin needs. It has no Logs code, so RUM-only customers download none of it.

Changes

Everything added is @internal.

findTrackedSession takes an optional sampleRate. It replaces the configured rate in isSampled only when passed, and 0 counts. Calls without it behave as before.

onInit gets registerCallQueue(queue). RUM drains every registered queue right after its own pre-start API calls, so plugin calls see the user and account set before start. Each call runs under callMonitored. A queue registered after start drains right away. Registering the same queue twice does nothing.

In the ticket and the RFC, RUM owned the queue. I moved it to the plugin, because calls made before init() had no queue to go to. The plugin creates and bounds it.

onRumStart gets RUM's real trackingConsentState and sessionManager.

Bundle size: rum Gzip goes from 65.56 KiB to 65.63 KiB (+0.07 KiB), rum_slim from 50.16 KiB to 50.23 KiB (+0.07 KiB). I'll confirm with the "Bundles Sizes Evolution" comment.

Type changes visible to external code. The plugin API is @experimental and its option types are exported from @datadog/browser-rum. registerCallQueue is now required on RumPluginOnInitOptions, and trackingConsentState and sessionManager are required on OnRumStartOptions. Plugins only receive these options, so only code that builds them by hand (tests) has to change. I added a cast in the tests that do.

Version skew. A newer plugin that calls registerCallQueue on an older RUM without it throws in onInit. The RumPlugin doc already says to use plugins matching the SDK version.

#5220 adds a second onRumStart call for late plugins. That call needs the two new fields once this lands.

This change was written with an AI agent. I'm least sure about the plugin owning the queue instead of RUM. What do you think?

Test instructions

I ran this on a local sandbox page with a plugin that registers a call queue. The queue is a minimal stand-in for BufferedObservable, since that isn't exposed in the CDN bundle. It queues a call that reads the user, a call that throws, and a call after it.

yarn build:bundle
yarn dev-server start
cat > sandbox/test-plugin-call-queue.html << 'EOF'
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Test plugin call queue</title>
    <script src="/datadog-rum.js"></script>
    <script>
      window.result = { order: [] }
      const buffered = []
      const queue = {
        subscribe(fn) { Promise.resolve().then(() => buffered.splice(0).forEach(fn)) },
        unbuffer() {},
      }
      const plugin = {
        name: 'call-queue-test',
        onInit({ registerCallQueue }) {
          window.result.hasRegisterCallQueue = typeof registerCallQueue
          registerCallQueue(queue)
          registerCallQueue(queue)
        },
        onRumStart({ trackingConsentState, sessionManager }) {
          window.result.onRumStart = {
            trackingConsentState: typeof trackingConsentState.tryToInit,
            findTrackedSession: typeof sessionManager.findTrackedSession,
            sampleRateZero: sessionManager.findTrackedSession(undefined, { sampleRate: 0 }) === undefined,
          }
        },
      }
      buffered.push(() => window.result.order.push('plugin call, user=' + JSON.stringify(window.DD_RUM.getUser())))
      buffered.push(() => { throw new Error('plugin call failure') })
      buffered.push(() => window.result.order.push('plugin call after failure'))
      DD_RUM.setUser({ id: 'u1' })
      DD_RUM.init({ clientToken: 'xxx', applicationId: 'xxx', proxy: '/proxy', plugins: [plugin] })
    </script>
  </head>
  <body></body>
</html>
EOF
agent-browser open http://localhost:8080/test-plugin-call-queue.html
agent-browser eval 'JSON.stringify(window.result)'
yarn dev-server stop
rm sandbox/test-plugin-call-queue.html

Expected output:

{"order":["plugin call, user={\"id\":\"u1\"}","plugin call after failure"],"hasRegisterCallQueue":"function","onRumStart":{"trackingConsentState":"function","findTrackedSession":"function","sampleRateZero":true}}

The plugin call runs after RUM replays setUser, the throwing call doesn't stop the next one, and onRumStart gets both new fields.

Unit tests:

yarn test:unit packages/browser-core/src/domain/session/sessionManager.spec.ts
yarn test:unit packages/browser-rum-core/src/boot/preStartRum.spec.ts
yarn test:unit packages/browser-rum-core/src/domain/plugins.spec.ts
yarn test:unit packages/browser-rum-core/src/boot/rumPublicApi.spec.ts

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

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum Salesforce 192.54 KiB 192.74 KiB +202 B +0.10% ✅
Rum 192.52 KiB 192.72 KiB +202 B +0.10% ✅
Rum Profiler 8.17 KiB 8.17 KiB 0 B 0.00% ✅
Rum Salesforce Profiler 8.17 KiB 8.17 KiB 0 B 0.00% ✅
Rum Salesforce Recorder 32.62 KiB 32.62 KiB 0 B 0.00% ✅
Rum Recorder 32.62 KiB 32.62 KiB 0 B 0.00% ✅
Logs 60.26 KiB 60.27 KiB +15 B +0.02% ✅
Rum Slim 148.45 KiB 148.64 KiB +195 B +0.13% ✅
Worker 24.23 KiB 24.23 KiB 0 B 0.00% ✅
Rum Shopify 223.58 KiB 223.78 KiB +202 B +0.09% ✅
Rum Shopify Profiler 8.17 KiB 8.17 KiB 0 B 0.00% ✅
Rum Shopify Recorder 4.85 KiB 4.85 KiB 0 B 0.00% ✅

@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Pipelines  Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
• Patch Coverage: 70.00%
• Overall Coverage: 78.04% (-0.04%)

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

This branch has not been deployed

No deployments
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