Repository navigation
feat(o11y): add setAttributes and removeAttributes - #865
Open
abelonogov-ld wants to merge 1 commit into
Open
abelonogov-ld wants to merge 1 commit into
abelonogov-ld wants to merge 1 commit into
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
Vadman97
approved these changes
Oct 29, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
LDObserve.setAttributes(attributes)/LDObserve.removeAttributes(keys)to the browser SDK (@launchdarkly/o11y, surfaced through@launchdarkly/observabilityand@launchdarkly/session-replay). This addresses the customer request for app-wide attributes (e.g. UTM parameters) on all telemetry, and matches the RN (#856), Android (#860), iOS (launchdarkly/swift-launchdarkly-observability#290), Flutter (#858), MAUI (#863), Java (#861) and Python (#859) PRs.globalThisunder aSymbol.forkey so the observability and session-replay bundles, which each bundle their own copy of o11y, share it.CustomBatchSpanProcessor.onStart(manual, fetch/XHR, error, flag evaluation, track, document load, user interaction), to logs (thelaunchdarkly.js.logspan and itslogevent), and to every metric data point. Spans take the values current when they start.highlight.session_id,session.idandhighlight.recordare ignored (logged in debug mode), as are invalid attribute values.setAttributes({ k: undefined })is ignored; useremoveAttributesto remove.start()withmanualStart, including to automatic spans emitted during init. Nothing is persisted; values survive session changes.README documents the API and how it differs from
addSessionProperties.How did you test this change?
globalAttributes.test.ts(14 tests): merge/remove, reserved keys, invalid values, snapshot immutability, calls before init and withmanualStart, the processor path used by automatic spans (values captured at start, later attributes win), manual spans, errors, logs and metrics.yarn turbo run build test typegen lintfor o11y, observability, highlight.run and session-replay, Prettier check, andyarn enforce-size(172.6 kB / 256 kB) pass.Are there any deployment considerations?
Additive; no behavior change unless the new API is used. Global attributes are added to metric data points, so they increase metric cardinality.
Note
Overview
Adds
LDObserve.setAttributes/removeAttributesso apps can attach page-scoped metadata (e.g. tenant, campaign) to all subsequent spans, logs, and metrics, including auto-instrumented telemetry.A new
globalAttributesstore merges keys in memory for the page lifetime, shared across observability and session-replay bundles viaglobalThis.setAttributes/removeAttributesbypass the pre-init call buffer so values apply before init ormanualStart. Globals only fill missing keys; explicit span/log/metric attributes and LD context keys win. Reserved keys (highlight.session_id,session.id,highlight.record) and invalid OTel values are dropped.Wiring:
CustomBatchSpanProcessor.onStartapplies globals to every span at start;ObserveSDKand the replayHighlightclient spreadgetGlobalAttributes()onto log events and metric data points. README andObserveAPI types document behavior vsaddSessionProperties.Tests: new
globalAttributes.test.tscovers merge/remove, precedence, pre-init usage, and telemetry paths.Reviewed by Cursor Bugbot for commit bb4b6d7. Bugbot is set up for automated code reviews on this repo. Configure here.