Skip to content

feat(react-native): link new sessions to the one they replace via session.previous_id - #870

Open
Vadman97 wants to merge 1 commit into
mainfrom
termag-vkorolik/cmvu4uwxn1hz8f7cqs2fo6mak
Open

Vadman97 wants to merge 1 commit into
mainfrom
termag-vkorolik/cmvu4uwxn1hz8f7cqs2fo6mak

Conversation

@Vadman97

@Vadman97 Vadman97 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Demo (test transcript): team-o11y:artifacts/sf8t4/test-output.txt

On React Native, every cold start (and every load after the 15-minute inactivity timeout) begins a new session, so a user journey that crosses a relaunch, such as tapping an email link, is split. With this change, when a JS load starts a new session in place of a persisted one, SessionManager keeps the replaced session's ID and adds session.previous_id to the session attributes. Those are spread onto the OTel Resource, so every span, log, error and metric of the new session carries it. Resumed sessions and first launches omit it. The attribute name and semantics match the browser SDK's session.previous_id (#857).

Testing

  • yarn workspace @launchdarkly/observability-react-native test: 17 files, 149 tests pass
  • yarn workspace @launchdarkly/observability-react-native typegen: clean
  • New tests in SessionManager.test.ts (stale session, cold start, resume, nothing persisted) and ObservabilityClient.test.ts (attribute present/absent on the Resource). 5 of them fail with the SessionManager change reverted.

Notes for the reviewer

  • The attribute lives on the Resource, so it covers the whole process lifetime of the new session. Because the session ID never rotates in-process, that equals the whole session for this JS load.
  • Not changed, but noticed: ObservabilityClient sets 'highlight.session_id': sessionAttributes.sessionId, and getSessionAttributes() has no sessionId key, so that resource attribute is always undefined. Worth fixing separately if anything still reads it.

🤖 Generated with Claude Code


Opened by termag ask for vkorolik: an agent run on sf8t4-10292244/observability-sdk, thread cmvu4uwxn1hz8f7cqs2fo6mak.

The run worked in its own clone of the committed code. termag checked its commits before pushing (descends from the base, no protected paths, authored by the asker, no secret-shaped strings); review the change as you would any other before marking it ready.

Follow-ups on the thread push here: termag ask sf8t4-10292244/observability-sdk --thread cmvu4uwxn1hz8f7cqs2fo6mak "…".

Opened from termag


Note

Overview
When a React Native JS load starts a new session instead of resuming a persisted one (inactivity timeout or cold start), SessionManager now remembers the replaced session ID and exposes it as session.previous_id in getSessionAttributes(), alongside existing session.id and session.start_time.

That attribute is omitted when the session is resumed within the resume window or when nothing was stored. Init failures clear the link. getPreviousSessionId() is added for direct access. Because ObservabilityClient merges session attributes onto the OTel Resource, the new field applies to spans, logs, errors, and metrics for the whole new session—matching browser SDK semantics for stitching journeys across relaunches.

Coverage adds SessionManager cases (stale, cold start, resume, empty store) and ObservabilityClient Resource assertions for presence/absence of session.previous_id.

Reviewed by Cursor Bugbot for commit 7c3a515. Bugbot is set up for automated code reviews on this repo. Configure here.

…sion.previous_id

When a JS load starts a new session in place of a persisted one (the
previous session timed out, or the app cold started), keep the replaced
session's ID and report it as `session.previous_id` in the session
attributes. They are spread onto the OTel Resource, so every span, log,
error and metric of the new session carries it, and sessions can be
chained across cold starts. Resumed sessions and first-ever launches
omit it. Mirrors the browser SDK's `session.previous_id`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Generated-by: termag
@Vadman97

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 7c3a515. Configure here.

@Vadman97
Vadman97 marked this pull request as ready for review October 30, 2026 06:07
@Vadman97
Vadman97 requested a review from a team as a code owner October 30, 2026 06:07
@Vadman97
Vadman97 enabled auto-merge (squash) October 30, 2026 06:07
@Vadman97
Vadman97 disabled auto-merge October 30, 2026 16:48

This branch has not been deployed

No deployments
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.

1 participant