Repository navigation
✨ [DEBUG-6444] Let SDKs add RUM plugins after init with addPlugin() - #5220
Conversation
Bundles Sizes Evolution
|
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 8a4872e | Docs | View more details | Give us feedback! |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
A plugin added before RUM starts can permanently miss onRumStart if 500 subsequent API calls overflow the startup buffer while consent is pending. RUM later starts without giving that plugin its event/error reporting callbacks.
🤖 Bits Code Review · Commit 58d7089
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 58d70891e0
ℹ️ 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".
Brings in the addPlugin() RUM API, and main with #5217. The conflict in preStartRum.ts is resolved by adding registerEventCollectedHook to the options that both the init plugins and the added plugins get. Environment: Datadog workspace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Environment: Datadog workspace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 78563663b5
ℹ️ 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".
Environment: Datadog workspace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Environment: Datadog workspace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 26f17795be
ℹ️ 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".
…5220) Environment: Datadog workspace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An SDK that loads separately, such as the Live Debugger SDK, can now attach a plugin to RUM itself, so customers don't have to load it before calling init(). - The plugin's onInit gets the same options as the plugins passed to init(). It can't abort the initialization, so what it returns is ignored, and its errors are reported without stopping init(). - Its onRumStart is called once RUM starts, or right away if it has already started. - A plugin added before init() waits for init(). Environment: Datadog workspace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Keep the added plugins waiting for RUM to start in their own list, rather than in the buffer of API calls made before RUM starts, which drops its oldest entries once it holds 500. - Call an added plugin's onRumStart once its asynchronous onInit has resolved, and skip it when onInit fails, as RUM doesn't start when the onInit of an init() plugin fails. - Add an example and the @hidden tag to the addPlugin() documentation, as docs/REVIEW.md requires for experimental public APIs. Environment: Datadog workspace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RUM waits for the onInit of the plugins passed to init() before it starts, so their hooks are registered before any event is assembled. Wait for the onInit of the plugins added before init() as well, while still ignoring what they return, so they can't abort init(). Environment: Datadog workspace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Plugins added with addPlugin() now start only once the init() plugins have let init() continue. If one of them aborts init(), the added plugins wait for a later init(), instead of starting for an init() that never starts RUM. - When the onInit of an added plugin returns false, skip its onRumStart, as when it fails. It still can't abort init(). Environment: Datadog workspace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Plugins added with addPlugin() started once the init() plugins let init() continue, even if init() then rejected the configuration. A later valid init() didn't start them again, so they kept the options of the rejected one. They now start once init() has accepted the configuration, which also covers an init() aborted by a plugin. RUM waits for their asynchronous onInit before starting, as for the init() plugins. Environment: Datadog workspace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
58a5ccd to
8ee97d3
Compare
There was a problem hiding this comment.
More details
The added-plugin path waits for asynchronous initialization before invoking onRumStart and isolates plugin failures. Static review found no actionable defects; runtime behavior remains unverified.
🤖 Bits Code Review · Commit 8ee97d3
addPlugin() started a plugin even when one with the same name was already added or passed to init(), so an SDK that adds itself while the customer also passes it to init() had its hooks and onRumStart called twice. Such a plugin is now ignored with a warning, whether it's added before or after init(). Environment: Datadog workspace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Motivation
DEBUG-6444
Exception Replay ships as a RUM plugin in the Live Debugger SDK (#5196). Today a plugin can only be passed to
init(), so the Live Debugger SDK has to load beforeDD_RUM.init(). With the async CDN snippet, customers then have to callDD_RUM.init()from insideDD_DEBUGGER.onReady(). That makes RUM wait for a second script, and if that script fails to load, RUM never starts.As discussed with the RUM team, this adds an API to add a plugin after
init(), so an SDK that loads separately can attach itself to RUM. It's a draft, to see what the API looks like before deciding on it.Changes
DD_RUM.addPlugin(plugin). The plugin'sonInitgets the same options as the plugins passed toinit(), so a plugin written for thepluginsoption works unchanged.onInitreturnsfalse, only its ownonRumStartis skipped. Its errors and rejected promises are reported withmonitorError, so they can't stopinit()or the other plugins.onRumStart: called once RUM has started and the plugin'sonInithas resolved. IfonInitthrows or rejects,onRumStartisn't called, as RUM doesn't start when theonInitof aninit()plugin fails. Plugins waiting for RUM to start are kept in their own list, so they can't be dropped from the 500-entry buffer of API calls made before RUM starts.init(): the plugin waits untilinit()has accepted the configuration, then starts. If a plugin abortsinit(), or validation rejects its configuration, it waits for a laterinit(). RUM waits for itsonInitbefore starting, as for theinit()plugins, so its hooks are registered before any event is assembled.init(), so it misses the events assembled before its hooks are registered.init(), is ignored with a warning, so an SDK that adds itself while the customer also passes it toinit()isn't started twice.Question for the RUM team: a plugin added with
addPluginisn't in the configuration telemetry, which is sent atinit(). Should we report it some other way? A usage telemetry feature would need a change in rum-events-format.This change was written with an AI agent.
Test instructions
yarn test:unit --spec packages/browser-rum-core/src/boot/preStartRum.spec.ts --spec packages/browser-rum-core/src/boot/rumPublicApi.spec.tsChecklist
Related PRs
addPluginto attach its RUM plugin.Reviewed with sol-loop: 1 round with gpt-6.2-sol on high. Sol verdict: approved
Created with Claude Opus 5.5 in Claude Code.