-
Notifications
You must be signed in to change notification settings - Fork 188
📝 [RUM-16097] Add migration skills for v4→v5 and v5→v6 SDK upgrades #4640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mormubis
wants to merge
5
commits into
main
Choose a base branch
from
adlrb/migration-skills-v4-v5-v5-v6
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
760725f
📝 Add migration skills for v4→v5 and v5→v6 SDK upgrades
mormubis 7d3ae15
📝 Fix sendLogsAfterSessionExpiration migration guidance
mormubis 83fcc5e
📝 Improve upgrade-browser-sdk-v7 skill based on evaluation findings
mormubis af32d7c
📝 Fix formatting
mormubis cafcecc
📝 Fix forwardErrorsToLogs guidance in upgrade-browser-sdk-v7 skill
mormubis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,268 @@ | ||
| --- | ||
| name: upgrade-browser-sdk-v5 | ||
| description: Use when upgrading Datadog Browser SDK from v4 to v5, when encountering removed options like proxyUrl, sampleRate, replaySampleRate, premiumSampleRate, allowedTracingOrigins, or deprecated APIs like addRumGlobalContext, removeUser | ||
| --- | ||
|
|
||
| # Upgrade Datadog Browser SDK to v5 | ||
|
|
||
| Systematic migration guide from v4 to v5. Follow steps 1-7 in order. Each step includes a search pattern to find affected code. | ||
|
|
||
| ## Step 1: Update SDK version | ||
|
|
||
| **CDN setup** — update script `src` URLs: | ||
|
|
||
| | v4 pattern | v5 replacement | | ||
| | -------------------------------------------------------- | -------------------------------------------------------- | | ||
| | `datadoghq-browser-agent.com/us1/v4/datadog-rum.js` | `datadoghq-browser-agent.com/us1/v5/datadog-rum.js` | | ||
| | `datadoghq-browser-agent.com/us1/v4/datadog-logs.js` | `datadoghq-browser-agent.com/us1/v5/datadog-logs.js` | | ||
| | `datadoghq-browser-agent.com/us1/v4/datadog-rum-slim.js` | `datadoghq-browser-agent.com/us1/v5/datadog-rum-slim.js` | | ||
|
|
||
| Replace `us1` with your site: `eu1`, `us3`, `us5`, `ap1`, `ap2`. For US1-FED, the pattern is flat: `datadog-rum-v5.js` (no site prefix). | ||
|
|
||
| Search: `grep -r "datadoghq-browser-agent.com.*v4" --include="*.html" --include="*.js" --include="*.ts" --include="*.tsx"` | ||
|
|
||
| **npm setup** — update `package.json` dependencies: | ||
|
|
||
| ``` | ||
| "@datadog/browser-rum": "^5.0.0" | ||
| "@datadog/browser-logs": "^5.0.0" | ||
| "@datadog/browser-rum-slim": "^5.0.0" | ||
| ``` | ||
|
|
||
| Then run your package manager (`npm install`, `yarn install`, etc.) and rebuild. | ||
|
|
||
| Also upgrade framework integrations to v5 if used: `@datadog/browser-rum-react`. | ||
|
|
||
| Search: `grep -r "@datadog/browser-" package.json` | ||
|
|
||
| ## Step 2: Replace deprecated init parameters | ||
|
|
||
| These v4 parameter names no longer exist in v5. Replace them: | ||
|
|
||
| | Deprecated parameter (v4) | Replacement (v5) | | ||
| | ------------------------- | ------------------------- | | ||
| | `proxyUrl` | `proxy` | | ||
| | `sampleRate` | `sessionSampleRate` | | ||
| | `allowedTracingOrigins` | `allowedTracingUrls` | | ||
| | `tracingSampleRate` | `traceSampleRate` | | ||
| | `trackInteractions` | `trackUserInteractions` | | ||
| | `premiumSampleRate` | `sessionReplaySampleRate` | | ||
| | `replaySampleRate` | `sessionReplaySampleRate` | | ||
|
|
||
| Search: `grep -rn 'proxyUrl\|sampleRate\|allowedTracingOrigins\|tracingSampleRate\|trackInteractions\|premiumSampleRate\|replaySampleRate' --include="*.js" --include="*.ts" --include="*.tsx" --include="*.html"` | ||
|
|
||
| **Note**: `sampleRate` matches broadly. Look specifically for init config objects — `sessionSampleRate` is the v5 name for the session sampling rate. | ||
|
|
||
| ## Step 3: Replace deprecated public APIs | ||
|
|
||
| These v4 API method names no longer exist in v5: | ||
|
|
||
| ### RUM APIs | ||
|
|
||
| | Deprecated API (v4) | Replacement (v5) | | ||
| | ------------------------------- | ------------------------------------ | | ||
| | `DD_RUM.removeUser` | `DD_RUM.clearUser` | | ||
| | `DD_RUM.addRumGlobalContext` | `DD_RUM.setGlobalContextProperty` | | ||
| | `DD_RUM.removeRumGlobalContext` | `DD_RUM.removeGlobalContextProperty` | | ||
| | `DD_RUM.getRumGlobalContext` | `DD_RUM.getGlobalContext` | | ||
| | `DD_RUM.setRumGlobalContext` | `DD_RUM.setGlobalContext` | | ||
|
|
||
| ### Logs APIs | ||
|
|
||
| | Deprecated API (v4) | Replacement (v5) | | ||
| | ----------------------------------- | ------------------------------------- | | ||
| | `DD_LOGS.addLoggerGlobalContext` | `DD_LOGS.setGlobalContextProperty` | | ||
| | `DD_LOGS.removeLoggerGlobalContext` | `DD_LOGS.removeGlobalContextProperty` | | ||
| | `DD_LOGS.getLoggerGlobalContext` | `DD_LOGS.getGlobalContext` | | ||
| | `DD_LOGS.setLoggerGlobalContext` | `DD_LOGS.setGlobalContext` | | ||
| | `logger.addContext` | `logger.setContextProperty` | | ||
| | `logger.removeContext` | `logger.removeContextProperty` | | ||
|
|
||
| Search: `grep -rn 'removeUser\|addRumGlobalContext\|removeRumGlobalContext\|getRumGlobalContext\|setRumGlobalContext\|addLoggerGlobalContext\|removeLoggerGlobalContext\|getLoggerGlobalContext\|setLoggerGlobalContext\|\.addContext\|\.removeContext' --include="*.js" --include="*.ts" --include="*.tsx"` | ||
|
|
||
| ## Step 4: Update Session Replay configuration | ||
|
|
||
| v5 changes several Session Replay defaults and behaviors: | ||
|
|
||
| ### 4a. `defaultPrivacyLevel` changed to `"mask"` | ||
|
|
||
| In v4, the default was `mask-user-input`. In v5, **all content is masked by default**. | ||
|
|
||
| To preserve v4 behavior (only mask user input): | ||
|
|
||
| ```js | ||
| DD_RUM.init({ | ||
| defaultPrivacyLevel: 'mask-user-input', | ||
| }) | ||
| ``` | ||
|
|
||
| ### 4b. Recording starts automatically | ||
|
|
||
| Sessions sampled for Session Replay are now automatically recorded. You no longer need to call `startSessionReplayRecording()`. | ||
|
|
||
| To preserve v4 behavior (manual recording start): | ||
|
|
||
| ```js | ||
| DD_RUM.init({ | ||
| startSessionReplayRecordingManually: true, | ||
| }) | ||
| ``` | ||
|
|
||
| ### 4c. Default `sessionReplaySampleRate` is now `0` | ||
|
|
||
| In v4, the default replay sample rate was 100. In v5, it's `0` — no replays unless you set it explicitly. | ||
|
|
||
| **Action**: Ensure `sessionReplaySampleRate` is explicitly set in your init config: | ||
|
|
||
| ```js | ||
| DD_RUM.init({ | ||
| sessionReplaySampleRate: 100, // or your desired rate | ||
| }) | ||
| ``` | ||
|
|
||
| ### 4d. `trackResources` and `trackLongTasks` must be explicit | ||
|
|
||
| When using `sessionReplaySampleRate` (instead of the removed `replaySampleRate` or `premiumSampleRate`), resources and long tasks are no longer collected by default. You must enable them explicitly: | ||
|
|
||
| ```js | ||
| DD_RUM.init({ | ||
| sessionReplaySampleRate: 100, | ||
| trackResources: true, | ||
| trackLongTasks: true, | ||
| }) | ||
| ``` | ||
|
|
||
| Search: `grep -rn 'sessionReplaySampleRate\|startSessionReplayRecording\|defaultPrivacyLevel\|trackResources\|trackLongTasks' --include="*.js" --include="*.ts" --include="*.tsx" --include="*.html"` | ||
|
|
||
| ## Step 5: Update changed APIs and behaviors | ||
|
|
||
| ### 5a. `beforeSend` must return a boolean | ||
|
|
||
| `beforeSend` callback functions should return `true` to keep the event or `false` to discard it. If no value is returned, the event is kept. This resolves TypeScript compilation errors. | ||
|
|
||
| ```js | ||
| beforeSend: (event, context) => { | ||
| // return true to keep, false to discard | ||
| return true | ||
| } | ||
| ``` | ||
|
|
||
| ### 5b. `beforeSend` action context: `context.event` → `context.events` | ||
|
|
||
| With frustration signals, an action event can be associated with multiple DOM events. `context.event` is replaced by `context.events` (array). | ||
|
|
||
| ```js | ||
| // v4 | ||
| beforeSend: (event, context) => { | ||
| if (event.type === 'action') { | ||
| const domEvent = context.event | ||
| } | ||
| } | ||
|
|
||
| // v5 | ||
| beforeSend: (event, context) => { | ||
| if (event.type === 'action') { | ||
| const domEvents = context.events // array | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### 5c. `beforeSend` performance entry is now a `PerformanceEntry` object | ||
|
|
||
| The `performanceEntry` in `beforeSend` context is now the raw `PerformanceEntry` object, not a JSON representation. The `PerformanceEntryRepresentation` type has been removed. | ||
|
|
||
| ### 5d. `startTime` removed from XHR `beforeSend` context | ||
|
|
||
| The `context.startTime` property has been removed from XHR resource `beforeSend` context. Use the `performanceEntry` instead. | ||
|
|
||
| ### 5e. `view.in_foreground_periods` removed from `beforeSend` | ||
|
|
||
| This attribute is now computed by the backend. Remove any `beforeSend` code that accesses `view.in_foreground_periods`. | ||
|
|
||
| ### 5f. Frustration signals collected automatically | ||
|
|
||
| Set `trackUserInteractions: true` to collect all user interactions, including frustration signals. The `trackFrustrations` parameter is no longer needed. | ||
|
|
||
| ### 5g. Resource method names are uppercase | ||
|
|
||
| Resource `method` field is now always uppercase (e.g., `GET`, `POST`). Update any dashboards or monitors filtering on `resource.method`. | ||
|
|
||
| ### 5h. `session.plan` field only on session events | ||
|
|
||
| The `session.plan` field is now only available on session events, not on all event types. Update any dashboard or monitor queries that reference `session.plan` on non-session events. | ||
|
|
||
| Search: `grep -rn 'beforeSend\|trackFrustrations\|PerformanceEntryRepresentation\|in_foreground_periods\|context\.event[^s]\|startTime' --include="*.js" --include="*.ts" --include="*.tsx"` | ||
|
|
||
| ## Step 6: Handle trusted events | ||
|
|
||
| v5 only listens to user-generated (trusted) events. Script-generated events are ignored by default. | ||
|
|
||
| If you rely on programmatic events (e.g., `dispatchEvent`), add the `__ddIsTrusted` attribute: | ||
|
|
||
| ```js | ||
| const click = new Event('click') | ||
| click.__ddIsTrusted = true | ||
| document.dispatchEvent(click) | ||
| ``` | ||
|
|
||
| Or allow all untrusted events globally: | ||
|
|
||
| ```js | ||
| DD_RUM.init({ | ||
| allowUntrustedEvents: true, | ||
| }) | ||
| ``` | ||
|
|
||
| Search: `grep -rn 'dispatchEvent\|new Event\|new MouseEvent\|new KeyboardEvent' --include="*.js" --include="*.ts" --include="*.tsx"` | ||
|
|
||
| ## Step 7: Update infrastructure | ||
|
|
||
| ### CSP `connect-src` domains changed | ||
|
|
||
| v5 sends data to new intake domains. Update your Content Security Policy: | ||
|
|
||
| | Datadog site | New `connect-src` domain | | ||
| | ------------ | ------------------------------------------ | | ||
| | US1 | `https://browser-intake-datadoghq.com` | | ||
| | US3 | `https://browser-intake-us3-datadoghq.com` | | ||
| | US5 | `https://browser-intake-us5-datadoghq.com` | | ||
| | EU1 | `https://browser-intake-datadoghq.eu` | | ||
| | US1-FED | `https://browser-intake-ddog-gov.com` | | ||
| | US2-FED | `https://browser-intake-us2-ddog-gov.com` | | ||
| | AP1 | `https://browser-intake-ap1-datadoghq.com` | | ||
|
|
||
| ### CORS headers for distributed tracing | ||
|
|
||
| v5 adds `tracecontext` as a default propagator. If you use `allowedTracingUrls`, your server must accept the `traceparent` header: | ||
|
|
||
| ``` | ||
| Access-Control-Allow-Headers: traceparent | ||
| ``` | ||
|
|
||
| ### Logs: `error.origin` removed | ||
|
|
||
| Update dashboards/monitors using `error.origin` to use `origin` instead. | ||
|
|
||
| ### Logs: console error prefix removed | ||
|
|
||
| The `"console error:"` prefix is removed from log messages. Update queries using this prefix to use `@origin:console` instead. | ||
|
|
||
| ### Logs: main logger decoupled | ||
|
|
||
| Runtime errors, network logs, report logs, and console logs no longer inherit the main logger's context, level, or handler. Use global context and dedicated init parameters instead. | ||
|
|
||
| ## Verification checklist | ||
|
|
||
| After upgrading, confirm: | ||
|
|
||
| - [ ] SDK loads without console errors | ||
| - [ ] No references to removed init parameters (`proxyUrl`, `sampleRate`, `replaySampleRate`, etc.) | ||
| - [ ] No references to removed APIs (`addRumGlobalContext`, `removeUser`, etc.) | ||
| - [ ] `beforeSend` callbacks return boolean values | ||
| - [ ] `beforeSend` action handlers use `context.events` (not `context.event`) | ||
| - [ ] `trackResources` and `trackLongTasks` explicitly set if using `sessionReplaySampleRate` | ||
| - [ ] Session Replay recording works (if `sessionReplaySampleRate` > 0) | ||
| - [ ] Distributed tracing working (no CORS errors from `traceparent` header) | ||
| - [ ] CSP `connect-src` updated to new intake domains | ||
| - [ ] Dashboards/monitors updated for uppercase `resource.method` | ||
| - [ ] No queries using `error.origin` (use `origin` instead) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AP2 should not be offered as a v4→v5 CDN replacement site: the repository changelog only adds AP2 deployment/types in the v6 line, so following this instruction for an AP2 setup would generate
/ap2/v5/...script URLs for a datacenter that v5 did not support. This is especially easy to hit because the same step tells users to mechanically replaceus1with one of the listed sites.Useful? React with 👍 / 👎.