Repository navigation
feat(react-native): add setAttributes and custom span/log processors - #862
Closed
abelonogov-ld wants to merge 3 commits into
Closed
abelonogov-ld wants to merge 3 commits into
abelonogov-ld wants to merge 3 commits into
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
| return release | ||
| }) | ||
|
|
||
| const TEST_FETCH_URL = 'http://example.test/api' |
| const localOptions = { | ||
| projectId: 'test-project-id', | ||
| serviceName: 'test-service', | ||
| backendUrl: 'http://127.0.0.1:1', |
| projectId: 'test-project-id', | ||
| serviceName: 'test-service', | ||
| backendUrl: 'http://127.0.0.1:1', | ||
| otlpEndpoint: 'http://127.0.0.1:1', |
This was referenced Oct 28, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
Author
|
Closing in favor of #856, which already implements setAttributes/removeAttributes for React Native. The example-legacy repro from this PR has been added there. |
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 global attributes and custom span/log processors to
@launchdarkly/observability-react-native. This addresses the customer request for app-wide attributes (e.g. UTM parameters) on all telemetry, and is one of a set of matching PRs across RN, Android, iOS, Flutter, MAUI, Java and Python that share the same semantics (see #858, #859, #860, #861, launchdarkly/swift-launchdarkly-observability#290).Global attributes
LDObserve.setAttributes(attributes)/LDObserve.removeAttributes(keys)maintain one process-wide, in-memory attribute map (immutable snapshot rebuilt only on change).onStart).highlight.session_idandsession.idare ignored (logged in debug mode), as are invalid attribute values.Custom processors (init-time options)
spanProcessors?: SpanProcessor[]andlogProcessors?: LogRecordProcessor[]onReactNativeOptions.onEnding,forceFlush,shutdown) is wrapped in try/catch, so a failing processor never breaks the SDK or the export.SpanProcessor,ReadableSpan,SdkSpan,LogRecordProcessor,SdkLogRecordandReadableLogRecordare re-exported so customers don't need matching OTel versions.README documents both APIs.
How did you test this change?
LDObserveand a realObservabilityClientwith stubbed exporters: attributes set before init apply immediately and reach telemetry recorded before init; reserved keys ignored; manual, fetch and error spans get globals with per-call values winning; logs get globals; remove takes effect; user processors see globals and their changes are exported even when another processor throws.tsc --noEmit,vitest run(147 tests), prettier check andvite buildpass. Removing the global-attributes span processor makes 5 span tests fail.Are there any deployment considerations?
Additive; no behavior change unless the new APIs or options are used. The global-attributes processor adds a cheap per-span / per-log loop over the snapshot. Global attributes are added to metric data points, so they increase metric cardinality.
Note
Overview
Adds process-wide global attributes and optional custom OpenTelemetry processors to
@launchdarkly/observability-react-native.LDObserve.setAttributes/removeAttributesmaintain an in-memory map merged onto spans (at start), logs, errors, auto-instrumented fetch spans, and metrics. Per-call attributes win over globals; reserved session keys (highlight.session_id,session.id) are ignored. Calls before async init update the store immediately (not the pre-init call buffer) so early telemetry still picks them up.Init options
spanProcessorsandlogProcessorsrun after the built-in global-attribute processors and before export, wrapped so throws cannot block export. Related OTel processor/span/log types are re-exported from the package. README and the legacy example app document and demo UTM-style globals.Reviewed by Cursor Bugbot for commit 135c413. Bugbot is set up for automated code reviews on this repo. Configure here.