🐛 [devext] support v7 session cookie and expose anonymous ID / account context - #4960
🐛 [devext] support v7 session cookie and expose anonymous ID / account context#4960mormubis wants to merge 5 commits into
Conversation
| .find(([cookieName]) => cookieName === name) | ||
| ?.[1] | ||
| } | ||
| const isV7 = window.DD_RUM?.version?.startsWith('7') || window.DD_LOGS?.version?.startsWith('7') |
There was a problem hiding this comment.
If the SDK hasn't initialized yet when the extension first reads, version is undefined and isV7 is false, so it falls back to _dd_s. On the next poll (once the SDK is up) it corrects itself. Not a real issue in practice but worth knowing.
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 8af253c | Docs | View more details | Give us feedback! |
5eb1c53 to
8af253c
Compare
Bundles Sizes Evolution
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8af253ce64
ℹ️ 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".
| .find(([cookieName]) => cookieName === name) | ||
| ?.[1] |
There was a problem hiding this comment.
Match the active v7 cookie by its configuration marker
issue: When multiple _dd_s_v2 cookies are visible, such as after changing trackSessionAcrossSubdomains or partitioned-cookie settings, this returns the first value regardless of its c marker. The v7 SDK deliberately selects the cookie whose marker matches its current cookie options in sessionInCookie.ts, so the extension can display and link to a stale or unrelated session instead of the one the SDK is using.
Useful? React with 👍 / 👎.
| ` | ||
| document.cookie = '_dd_s=isExpired=1; expires=${expires}; path=/' | ||
| if (document.cookie.includes('_dd_s_v2=')) { | ||
| document.cookie = '_dd_s_v2=isExpired=1; expires=${expires}; path=/' |
There was a problem hiding this comment.
Preserve v7 cookie attributes when ending the session
issue: For v7 applications using trackSessionAcrossSubdomains or usePartitionedCrossSiteSessionCookie, this assignment omits the original Domain or Partitioned attributes and therefore creates or updates a different cookie rather than the SDK's active _dd_s_v2. Because the SDK continues selecting the original cookie by its c marker, clicking “End current session” does not actually end that session; use the SDK configuration to write the expiration with matching cookie attributes.
Useful? React with 👍 / 👎.
| internalContext: window.DD_RUM?.getInternalContext?.(), | ||
| globalContext: window.DD_RUM?.getGlobalContext?.(), | ||
| user: window.DD_RUM?.getUser?.(), | ||
| account: window.DD_RUM?.getAccount?.(), |
There was a problem hiding this comment.
Avoid reporting extension polling as getAccount usage
issue: Opening the Infos tab now invokes RUM's instrumented getAccount() method every two seconds. That method records the get-account telemetry usage feature, so merely inspecting a page marks the API as customer-used even when the application never calls it, contaminating API-adoption measurements; retrieve the account through a non-instrumented inspection path instead.
AGENTS.md reference: AGENTS.md:L120-L120
Useful? React with 👍 / 👎.
Motivation
SDK v7 renamed the session cookie from
_dd_sto_dd_s_v2, so the extension was showing empty session data for any v7 app. v7 also added anaid(anonymous ID) field in the cookie and agetAccount()API that the extension wasn't exposing. Jira: RUM-17172.Changes
In
useSdkInfos.ts, refactored cookie reading into afindCookieValue()helper. The new cookie name_dd_s_v2is preferred only when a v7 SDK is detected on the page (DD_RUM.versionorDD_LOGS.versionstarts with "7"), falling back to_dd_sotherwise. This prevents a stale_dd_s_v2left over from a previous v7 session from shadowing an active v6 session. Theaidcookie field is mapped toanonymousIdfor readability. AddedgetAccount()calls for both RUM and Logs.In
infosTab.tsx, the new fields show up in the panel: anonymous ID under the cookie section, account under RUM and Logs.endSession()also expires_dd_s_v2, but only if it already exists — unconditionally writing it on a v6 page would create a phantom cookie that shadows the real v6 session on next load.Test instructions
yarn dev, openhttp://localhost:8080) and open the Infos tab — session data should show, including the anonymous ID.DD_RUM.setAccount({ id: 'test' })in the console — Account should appear under RUM._dd_s_v2should be expired in Application → Cookies._dd_smanually and verify session shows. Click End session —_dd_sexpires and no_dd_s_v2is created._dd_sand_dd_s_v2manually on a non-v7 page — extension should show_dd_s. On a v7 page with both cookies — extension should show_dd_s_v2.Checklist