Repository navigation
feat(maui): add SetAttributes and RemoveAttributes - #863
Open
abelonogov-ld wants to merge 7 commits into
Open
abelonogov-ld wants to merge 7 commits into
abelonogov-ld wants to merge 7 commits into
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
vadim-korolik
approved these changes
Oct 29, 2026
abelonogov-ld
added a commit
that referenced
this pull request
Nov 6, 2026
## Summary Adds a global attributes API to the Android observability SDK. This is one of a set of matching PRs across SDKs that share the same semantics (see #858, #859, #861, #856, #863, launchdarkly/swift-launchdarkly-observability#290). - `LDObserve.setAttributes(Attributes)` and `LDObserve.setAttributes(Map<String, Any?>)` merge attributes by key into one in-memory, process-wide map; `LDObserve.removeAttributes(Collection<String>)` removes keys. - Applied to every span (values captured at span start), every log record (including crash reports) and every metric data point recorded after the call, including the launch-time histogram. - Precedence: per-call attributes > globals > resource. Globals only fill missing keys and never overwrite. Upstream `OtelRumConfig.setGlobalAttributes` is intentionally not used, because its appenders overwrite per-call values. Instead, internal span and log processors are registered ahead of the SDK's sampling and export processors, and metric record methods merge globals under per-call values. - `session.id` and `highlight.session_id` are ignored (a warning is logged). - Not persisted and not cleared on session rotation. Calls made before the SDK initializes take effect, because the store exists independently of the SDK instance. - Reads are a lock-free load of an immutable snapshot; writes rebuild it under a lock. - README documents the API with a Kotlin example. ## How did you test this change? - New JVM unit tests (`GlobalAttributesStoreTest`, `GlobalAttributesPipelineTest`): merge/remove, re-setting a key with a different value type, reserved keys, per-call precedence, concurrent writers, set-before-init through `LDObserve`, globals captured at span start, and globals reaching exported spans, logs and metric data points through real OpenTelemetry providers wired like the SDK. - `./gradlew :lib:compileDebugKotlin :lib:test` passes (559 tests, debug and release). ## Are there any deployment considerations? - `ObservabilityOptions` is unchanged. The only API change is three new methods on `Observe` (inherited by `LDObserve` and its companion), with default implementations, so Kotlin implementers need no changes. - Java and MAUI callers use `LDObserve.Companion.setAttributes(...)` / `removeAttributes(...)`, like the other `LDObserve` methods. #863 (MAUI) is stacked on this PR. - Global attributes are added to metric data points, so they increase metric cardinality. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > Adds **process-wide global attributes** on the Android observability SDK via `LDObserve.setAttributes` (OTel `Attributes` or plain map) and `LDObserve.removeAttributes`. > > Globals are stored in a singleton **`GlobalAttributesStore`** so calls **before SDK init** still apply once the pipeline starts. They are merged into **spans** (snapshot at span start), **logs** (via new processors registered ahead of sampling/export), and **metrics** (including launch-time histograms), with **per-call attributes winning** over globals and reserved session keys ignored with a warning. README and the compose e2e app document/repro UTM-style globals and precedence. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 7e24d72. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
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 global attributes to the .NET MAUI SDK, matching the other SDKs in this series (#858, #859, #860, #861, #856, launchdarkly/swift-launchdarkly-observability#290):
LDObserve.SetAttributes(IDictionary<string, object?>)/LDObserve.RemoveAttributes(IEnumerable<string>)merge into the native SDK's process-wide, in-memory map.session.idandhighlight.session_idare ignored on both platforms.LDObservemethods): calls are buffered in a thread-safe C# store and replayed into native right before the nativeStart, so telemetry recorded during native startup carries them too. After that, calls go straight to native under the same lock, so a racing write can't be overtaken by older buffered values.TelemetrySpan,System.Net.Http,RecordError) are exported through the native tracer viaLDTraceExporter/TraceBuilderAdapter, so native globals apply to them; Activity tags are copied after the native span starts, so they win over globals. Because the native span is created at export, a .NET span gets the globals current when its Activity ends.ObservabilityBridge.setAttributes/removeAttributes, Swift@objcstaticsetAttributes:/removeAttributes:, plus the iOS bindingApiDefinition.Custom span/log processors are intentionally not added for MAUI: telemetry is produced natively, and .NET processors would need a native→.NET callback for every span and log.
How did you test this change?
tests/LDObservability.Tests(12 tests) for the pending store: merge/remove/replay ordering, reserved keys, null values, snapshotting, and concurrent writes during bind.dotnet testpasses../gradlew :LDObserve:assembleRelease), the iOS xcframework (scripts/build_xcframework.sh, Xcode 27.1, against the chore: release main #290 checkout), both bindings,LDObservabilityfornet9.0-androidandnet9.0-ios, andMauiSample9for Android and the iOS simulator (the iOS sample needs-p:ValidateXcodeVersion=falselocally because .NET for iOS 26.2 expects Xcode 26.2).Are there any deployment considerations?
Package.resolvedwill need OpenTelemetry-Swift ≥ 2.5.0 when the iOS dependency is bumped (left out of this PR).Note
Overview
Adds process-wide global attributes to the .NET MAUI observability API via
LDObserve.SetAttributesandLDObserve.RemoveAttributes, aligned with the other mobile SDKs. Merged keys attach to subsequent spans, logs, and metrics (including native auto-instrumentation); per-call attributes still override globals. Reserved keyssession.idandhighlight.session_idare stripped, andnullvalues are ignored.Unlike other
LDObservecalls, pre-init usage is supported: a newGlobalAttributesBufferholds set/remove operations under a lock and replays them into native immediately beforeStartviaNativeGlobalAttributesSinkand new Android Kotlin / iOS Swift bridge methods (plus iOS binding exports). After bind, writes go straight to the native store.Documentation and the sample app exercise UTM-style globals set before init and per-call override on logs/spans. A new
LDObservability.TestsxUnit project linksGlobalAttributesBufferfor merge, remove, reserved keys, and concurrent-bind coverage.Reviewed by Cursor Bugbot for commit a3c9fda. Bugbot is set up for automated code reviews on this repo. Configure here.