Skip to content

feat(flutter): add setAttributes and removeAttributes - #858

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

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

Conversation

@abelonogov-ld

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

Copy link
Copy Markdown
Contributor

Summary

Adds global attributes to the Flutter observability SDK. This is one of a set of matching PRs across SDKs that share the same semantics (see #859, #860, #861, #856, #863, launchdarkly/swift-launchdarkly-observability#290).

  • LDObserve.setAttributes(Map<String, Object?> attributes) merges by key into one process-wide, in-memory map; LDObserve.removeAttributes(List<String> keys) removes keys.
  • Where globals apply:
    • Every span recorded from Dart: manual spans, flag evaluations, errors and Dart lifecycle spans, plus track, screen-view and click spans on web. An internal span processor, registered ahead of export, fills them in on span start.
    • Every log recorded through LDObserve.recordLog and captured debugPrint / print output.
    • On iOS and Android, the properties of track, screen-view and click events forwarded to the native SDK.
  • Precedence: per-call attributes > globals > resource. Globals only fill keys that aren't already set; a span takes the values current when it starts.
  • Reserved keys: session.id and highlight.session_id are ignored, as are values that can't be attributes (including null).
  • Lifetime: works before init, kept in memory for the life of the process, not cleared when the session changes, never persisted. Readers see an immutable snapshot rebuilt only on change.
  • Not covered:
  • README has a new "Global attributes" section.

How did you test this change?

  • New test/global_attributes_test.dart: merge and remove, reserved keys and invalid values ignored, immutable snapshot, fill precedence.
  • New test/global_attributes_pipeline_test.dart runs Otel.setup against a mocked native bridge:
    • globals set before init reach exported spans;
    • per-call properties and span.setAttribute win over globals;
    • spans keep their start-time values, and removed keys stop appearing;
    • error spans and logs carry globals, with per-call properties winning;
    • screen views, clicks and track events forwarded to native carry globals beneath their own properties.
  • test/web_exporters_test.dart: web track, screen-view, click and log spans carry globals without overriding the SDK's event.* keys.
  • test/public_api_test.dart covers the new LDObserve signatures.
  • dart format, flutter analyze (clean) and flutter test (292 tests) pass.

Are there any deployment considerations?

None. Two static methods are added to LDObserve; nothing changes unless an app calls them.


Note

Overview
Adds process-wide global attributes to the Flutter observability SDK via LDObserve.setAttributes and LDObserve.removeAttributes, aligned with matching SDK work elsewhere.

Globals merge in memory (safe before init), ignore reserved session keys and invalid values, and attach to Dart-recorded telemetry: spans get them at start through a new GlobalAttributesSpanProcessor; logs and native-forwarded track/screen-view/click properties are filled so per-call keys win. README documents precedence and limits (no Dart metrics API; native-only crash/lifecycle telemetry unchanged).

The example app gains repro.dart to demo UTM-style globals and expected LaunchDarkly row attributes. Coverage includes store/unit tests, a full pipeline test against the mocked native bridge, and web exporter assertions.

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

Co-authored-by: Cursor <cursoragent@cursor.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3b0ee45. Configure here.

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