Skip to content

feat(android): add setAttributes and removeAttributes - #860

Open
abelonogov-ld wants to merge 4 commits into
mainfrom
andrey/global-attributes-android
Open

abelonogov-ld wants to merge 4 commits into
mainfrom
andrey/global-attributes-android

Conversation

@abelonogov-ld

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

Copy link
Copy Markdown
Contributor

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. feat(maui): add SetAttributes and RemoveAttributes #863 (MAUI) is stacked on this PR.
  • Global attributes are added to metric data points, so they increase metric cardinality.

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.

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

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@abelonogov-ld abelonogov-ld changed the title feat(android): add setAttributes and custom span/log processors feat(android): add setAttributes and removeAttributes Oct 28, 2026
abelonogov-ld and others added 2 commits October 28, 2026 17:17
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