Skip to content

feat(react-native): add LaunchDarkly context keys to all telemetry - #869

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

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

Conversation

@Vadman97

@Vadman97 Vadman97 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

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

What and why

The React Native SDK only put context keys on the LD.identify log and LD.track spans, so you couldn't tie other RN rows to a user or device. Now every identify stores the context keys, and they're stamped as context.contextKeys.<kind> (same names as web) on all logs, errors, spans (manual, track, flag, network, console.error) and metrics. This uses the existing shared-attribute processors.

  • InstrumentationManager.setContextKeyAttributes replaces the stored keys on each call and fills getContextKeyAttributes().
  • An internal _LDObserve._setContextKeys call is buffered before init and goes through ObservabilityClient.setContextKeys.
  • afterIdentify sets the keys first, whatever the identify status, as web does. The LD.identify log keeps its bare user/device fields for back-compat.

Testing

  • yarn workspace @launchdarkly/observability-react-native test: 18 files, 155 tests pass, including the new src/client/ContextKeys.test.ts (12 tests). They cover log, error, console.error, manual/track/flag/XHR spans, all metric kinds, multi-context, re-identify replacing keys, a non-completed identify, and an identify before init being buffered.
  • yarn workspace @launchdarkly/observability-react-native typegen: passes.

Open questions

  • Keys are also set when identify returns error/shed, to match web. A later identify overwrites them. Should RN only set them on completed?
  • Network spans are tested through XHR, not fetch: jsdom has no fetch. Both go through the same span processor.

🤖 Generated with Claude Code


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

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 sf4t1-10292244/observability-sdk --thread cmvu4tz271hq2f7cqjodjfd0a "…".

Opened from termag


Note

Overview
React Native observability now attaches LaunchDarkly evaluation context to every signal, not only LD.identify / track paths. On each afterIdentify, the plugin pushes context keys through _LDObserve._setContextKeys (buffered before init), which lands in InstrumentationManager.setContextKeyAttributes and replaces the stored snapshot as context.contextKeys.<kind>—aligned with the web SDK naming.

Those keys merge with global attributes in getSharedAttributes(), so logs, errors, manual/track/flag/network spans, and metrics pick them up via the existing global-attribute processors. Keys are updated on every identify (including non-completed statuses, like web); re-identify replaces the set. The LD.identify log still includes bare user/device fields for back-compat.

Adds ContextKeys.test.ts (store/replace, metrics, plugin identify, multi-context, pre-init buffering, re-identify, failed identify).

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

Store the current context keys on every identify and stamp them as
`context.contextKeys.<kind>` on all logs, errors, spans and metrics,
matching the web SDK. Keys are replaced (not merged) on each identify
and are set regardless of identify status, as on web. An identify made
before the SDK initializes is buffered and applied in order. The bare
`user`/`device` fields on the `LD.identify` log are kept.

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 a770a61. 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.

2 participants