Skip to content

Conversation

@johnHackworth
Copy link
Collaborator

Motivation

This PR changes the way we generate UUIDs so session ids are no longer random, but based on a seed that combines the 15-minute period of time the session was create, the app id and the anonymous user id.
This way, any session created in the same device within this 15 minutes time divisions would have the exact same id. As such, if any of the conditions that cause sessions to be terminated and created rapidly happens, all the microsessions would have a constant id, in practice consolidating them as a single session.

Changes

This PR changes how we generate UUIDs: When anonymous_id and app_id are available, we generate the UUID based on them. If they are not available, we still generate a random id.

Test instructions

  1. Make sure you are testing this branch in an environment where trackAnonymousUsers is set to true and it's not loading the logs SDK in parallel to RUM SDK
  2. Load your site and make sure a session is created.
  3. Force the SDK to create a new session (by, for example, editing the cookie to change the expire value to 0 and then reloading the page: Don't delete the cookie or use the extension to kill the session, since this would delete the anonymous_id and change the generated session id)
  4. check the session id of the new session is the same than the previous one. Let at least 15 minutes pass and repeat the process: the session id should now be different, but still consistent if you keep trying (for another 15 minutes)

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.

@johnHackworth johnHackworth requested a review from a team as a code owner December 5, 2025 15:59
@datadog-datadog-prod-us1
Copy link

⚠️ Tests

⚠️ Warnings

🧪 4 Tests failed

generateUUID deterministic UUID generation should generate deterministic UUID that changes over time windows from Chrome Headless 139.0.0.0 (Linux 0.0.0) (Datadog)
Error: Expected '1dec5da1-23a1-4b2c-3d4e-5f6789012000' not to be '1dec5da1-23a1-4b2c-3d4e-5f6789012000'.
    at <Jasmine>
    at UserContext.<anonymous> (/go/src/github.com/DataDog/browser-sdk/packages/core/src/tools/utils/stringUtils.spec.ts:56:25 <- /tmp/_karma_webpack_477253/commons.js:126747:31)
    at <Jasmine>
rum sessions › session renewal › create a new View when the session is renewed › async from rum/sessions.scenario.ts (Datadog)
createTest.ts:244:3 async

[chromium] › ../lib/framework/createTest.ts:244:3 › rum sessions › session renewal › create a new View when the session is renewed › async 

    Error: expect(received).not.toBe(expected) // Object.is equality

    Expected: not "1dec5d37-fe52-4bfb-3d54-4c13b923662d"

       at rum/sessions.scenario.ts:16

...
rum sessions › session renewal › create a new View when the session is renewed › bundle from rum/sessions.scenario.ts (Datadog)
createTest.ts:244:3 bundle

[chromium] › ../lib/framework/createTest.ts:244:3 › rum sessions › session renewal › create a new View when the session is renewed › bundle 

    Error: expect(received).not.toBe(expected) // Object.is equality

    Expected: not "1dec5d37-fe52-4bfb-3d54-b6af029f7653"

       at rum/sessions.scenario.ts:16

...
rum sessions › session renewal › create a new View when the session is renewed › npm from rum/sessions.scenario.ts (Datadog)
createTest.ts:244:3 npm

[chromium] › ../lib/framework/createTest.ts:244:3 › rum sessions › session renewal › create a new View when the session is renewed › npm 

    Error: expect(received).not.toBe(expected) // Object.is equality

    Expected: not "1dec5d37-fe52-4bfb-3d54-88c6a540b9f4"

       at rum/sessions.scenario.ts:16

...
View all

ℹ️ Info

❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 04c0173 | Docs | Datadog PR Page | Was this helpful? 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.

2 participants