Skip to content

feat(maui): add SetAttributes and RemoveAttributes - #863

Open
abelonogov-ld wants to merge 5 commits into
andrey/global-attributes-androidfrom
andrey/global-attributes-maui
Open

abelonogov-ld wants to merge 5 commits into
andrey/global-attributes-androidfrom
andrey/global-attributes-maui

Conversation

@abelonogov-ld

@abelonogov-ld abelonogov-ld commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #860 (Android setAttributes). Depends on launchdarkly/swift-launchdarkly-observability#290 (iOS setAttributes). Retarget to main once #860 merges.

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.
  • Applied to every span, log and metric recorded afterwards, including the native SDK's automatic telemetry. Globals only fill keys the signal doesn't already carry (per-call attributes win). Not persisted; survive session rotation. session.id and highlight.session_id are ignored on both platforms.
  • Safe before init (unlike other LDObserve methods): calls are buffered in a thread-safe C# store and replayed into native right before the native Start, 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.
  • .NET-side spans (Activity API, TelemetrySpan, System.Net.Http, RecordError) are exported through the native tracer via LDTraceExporter / 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.
  • Native bridge: Kotlin ObservabilityBridge.setAttributes/removeAttributes, Swift @objc static setAttributes: / removeAttributes:, plus the iOS binding ApiDefinition.

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?

  • New xUnit project tests/LDObservability.Tests (12 tests) for the pending store: merge/remove/replay ordering, reserved keys, null values, snapshotting, and concurrent writes during bind. dotnet test passes.
  • Built the Android native bridge (./gradlew :LDObserve:assembleRelease), the iOS xcframework (scripts/build_xcframework.sh, Xcode 27.1, against the chore: release main #290 checkout), both bindings, LDObservability for net9.0-android and net9.0-ios, and MauiSample9 for Android and the iOS simulator (the iOS sample needs -p:ValidateXcodeVersion=false locally because .NET for iOS 26.2 expects Xcode 26.2).
  • Not yet verified at runtime on a device or simulator.

Are there any deployment considerations?


Note

Overview
Adds process-wide global attributes to the .NET MAUI observability API via LDObserve.SetAttributes and LDObserve.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 keys session.id and highlight.session_id are stripped, and null values are ignored.

Unlike other LDObserve calls, pre-init usage is supported: a new GlobalAttributesBuffer holds set/remove operations under a lock and replays them into native immediately before Start via NativeGlobalAttributesSink and 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.Tests xUnit project links GlobalAttributesBuffer for 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.

abelonogov-ld and others added 2 commits October 28, 2026 16:38
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

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