Skip to content

Conversation

@mormubis
Copy link
Contributor

@mormubis mormubis commented Jan 9, 2026

Motivation

The Session Manager Revamp (SMR) will require our session manager to operate asynchronously and postpone the SDK initialization until the session is ready.

Changes

onReady callback in session manager that propagates through all places using the start of the session.

Test instructions

TBD

Checklist

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

@cit-pr-commenter
Copy link

cit-pr-commenter bot commented Jan 9, 2026

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 165.85 KiB 166.14 KiB +297 B +0.17%
Rum Profiler 4.33 KiB 4.33 KiB 0 B 0.00%
Rum Recorder 24.48 KiB 24.48 KiB 0 B 0.00%
Logs 56.21 KiB 56.42 KiB +218 B +0.38%
Flagging 944 B 944 B 0 B 0.00%
Rum Slim 123.05 KiB 123.33 KiB +288 B +0.23%
Worker 23.63 KiB 23.63 KiB 0 B 0.00%
🚀 CPU Performance
Action Name Base CPU Time (ms) Local CPU Time (ms) 𝚫%
RUM - add global context 0.0042 0.0126 +200.00%
RUM - add action 0.0128 0.031 +142.19%
RUM - add error 0.0131 0.0358 +173.28%
RUM - add timing 0.0025 0.0066 +164.00%
RUM - start view 0.0032 0.0087 +171.87%
RUM - start/stop session replay recording 0.0007 0.0021 +200.00%
Logs - log message 0.0157 0.0299 +90.45%
🧠 Memory Performance
Action Name Base Memory Consumption Local Memory Consumption 𝚫
RUM - add global context 25.67 KiB 26.31 KiB +653 B
RUM - add action 49.89 KiB 89.80 KiB +39.92 KiB
RUM - add timing 25.12 KiB 25.11 KiB -16 B
RUM - add error 53.52 KiB 99.54 KiB +46.02 KiB
RUM - start/stop session replay recording 24.03 KiB 25.09 KiB +1.06 KiB
RUM - start view 424.27 KiB 438.32 KiB +14.05 KiB
Logs - log message 45.55 KiB 96.06 KiB +50.50 KiB

🔗 RealWorld

@datadog-official
Copy link

datadog-official bot commented Jan 9, 2026

⚠️ Tests

Fix all issues with Cursor

⚠️ Warnings

🧪 2 Tests failed

telemetry › collect errors related to session initialization › logs from telemetry.scenario.ts (Datadog) (Fix with Cursor)
createTest.ts:244:3 logs

[Edge] › ../lib/framework/createTest.ts:244:3 › telemetry › collect errors related to session initialization › logs 

    Error: expect(received).toHaveLength(expected)

    Expected length: 1
    Received length: 0
    Received array:  []

...
telemetry › collect errors related to session initialization › rum from telemetry.scenario.ts (Datadog) (Fix with Cursor)
createTest.ts:244:3 rum

[Edge] › ../lib/framework/createTest.ts:244:3 › telemetry › collect errors related to session initialization › rum 

    Error: expect(received).toHaveLength(expected)

    Expected length: 1
    Received length: 0
    Received array:  []

...

ℹ️ Info

❄️ No new flaky tests detected

🎯 Code Coverage
Patch Coverage: 76.32%
Overall Coverage: 77.17% (-0.09%)

View detailed report

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 70449f2 | Docs | Datadog PR Page | Was this helpful? Give us feedback!

@mormubis mormubis force-pushed the adlrb/async-session-manager branch from dc49dab to cf26f2b Compare January 12, 2026 13:28
@mormubis mormubis force-pushed the adlrb/async-session-manager branch from 7b107f7 to 6e0e1f7 Compare January 16, 2026 14:58
Comment on lines +20 to +31
function check() {
try {
const result = callback()
if (result && typeof (result as any).then === 'function') {
;(result as Promise<T>).then(handleResult, handleError)
} else {
handleResult(result as T)
}
} catch (error) {
handleError(error as Error)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: you can simplify all this as:

function check() {
  Promise.resolve().then(callback).then(handleResult, handleError)
}

And sometimes in the future:

function check() {
  Promise.try(callback).then(handleResult, handleError)
}

beforeEach(async () => {
LOGS = makeLogsPublicApi(startLogs)
LOGS.init(DEFAULT_INIT_CONFIGURATION)
await waitFor(() => startLogs.calls.count() > 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: not sure to understand why you put waitFor in many places. When I remove those waitFor, tests are still passing?

Also suggestion: use collectAsyncCalls instead of waitFor (it'll be more efficient)

await collectAsyncCalls(startLogs, 1)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was super flaky for me. Most of the time, it varies between 3 or 25 tests failing. So I chose to add waitFor everywhere.

// acquire lock
currentLock = createLock()
persistWithLock(currentStore.session)
safePersist(() => persistWithLock(currentStore.session))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Why do we need this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the session manager inits before the tryInit, so it outside of the monitor call.

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.

3 participants