Skip to content

feat: Tracing API polishing + Distributed tracing Docs#464

Merged
abelonogov-ld merged 30 commits intomainfrom
andrey/maui-dist-doc
Apr 9, 2026
Merged

feat: Tracing API polishing + Distributed tracing Docs#464
abelonogov-ld merged 30 commits intomainfrom
andrey/maui-dist-doc

Conversation

@abelonogov-ld
Copy link
Copy Markdown
Contributor

@abelonogov-ld abelonogov-ld commented Apr 9, 2026

Summary

  • Distributed tracing Docs
  • Activity Microsoft API exposed
  • Fix StartRootActivity to always restore Activity.Current after creating the root activity, preventing permanent loss of the ambient activity context.

Problem

StartRootActivity saves Activity.Current into previous and sets it to null to create a parentless activity. However, it only restored previous when StartActivity returned null. On success, Activity.Current was left pointing to the new root activity — and when that activity was later disposed, Activity.Current reverted to its parent (null), permanently losing the original ambient context.

This made StartRootActivity behave differently from StartRootSpan, which uses DeactivateNewSpan to leave Activity.Current untouched. The README documents these as "equivalent," but they had different side effects on ambient context.

Fix

Unconditionally restore Activity.Current = previous after creating the activity, matching the behavior of StartRootSpan.

Test plan

  • Verify that Activity.Current is preserved after calling StartRootActivity
  • Verify the returned root activity has no parent
  • Verify StartRootActivity and StartRootSpan behave equivalently with respect to ambient context

Note

Medium Risk
Adds new public tracing surface area (Activity/ActivitySource and parent-context span overloads) and changes ambient Activity.Current handling in StartRootActivity, which could affect trace correlation if incorrect.

Overview
Tracing API polish + distributed tracing docs. LDObserve now supports starting spans with an explicit parent SpanContext (and optional SpanKind) to enable manual context propagation across threads, and it exposes a .NET-native Activity API (GetActivitySource, StartActivity, StartRootActivity).

StartRootActivity is fixed to always restore the previous Activity.Current after creating a root activity, avoiding accidental loss of ambient context. Documentation is expanded with a new docs/distributed-tracing.md cookbook and README updates (log/span context examples, span.AddEvent, root spans/activities), and the sample app adds a polling demo that creates child spans from captured context.

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

- Introduced `triggerLogWithContext` method in ViewModel to log messages with OpenTelemetry span context.
- Added a button in MainActivity to trigger the new logging functionality, enhancing observability in detached threads.
- Cleaned up imports in `LDObserve.kt`, `ObservabilityHookExporter.kt`, `ViewModel.kt`, `ObservabilityServiceTasks.kt`, `SamplingE2ETest.kt`, and `DisablingConfigOptionsE2ETest.kt` by removing the unused `recordLog` import.
- Updated `recordLog` method signature in `Observe.kt` to provide default values for attributes and spanContext, simplifying its usage.
- Introduced a new button in MainPage.xaml to trigger logging with OpenTelemetry span context.
- Implemented OnTriggerLogWithContextClicked method in MainPage.xaml.cs to log messages with associated span context.
- Updated LDObserve to support optional span context in the RecordLog method, enhancing trace-log correlation capabilities.
…ization logic

- Renamed the TryInitializeAll method to InitializeAll for clarity.
- Updated the initialization logic to only call LDObserve.Initialize if observability options are enabled.
- Adjusted the Register method to call the renamed InitializeAll method.
- Introduced `triggerLogWithContext` method in ViewModel to log messages with OpenTelemetry span context.
- Added a button in MainActivity to trigger the new logging functionality, enhancing observability in detached threads.
- Cleaned up imports in `LDObserve.kt`, `ObservabilityHookExporter.kt`, `ViewModel.kt`, `ObservabilityServiceTasks.kt`, `SamplingE2ETest.kt`, and `DisablingConfigOptionsE2ETest.kt` by removing the unused `recordLog` import.
- Updated `recordLog` method signature in `Observe.kt` to provide default values for attributes and spanContext, simplifying its usage.
* andrey/maui-network:
  feat: MAUI trace log correlation (#461)
@abelonogov-ld abelonogov-ld requested a review from a team as a code owner April 9, 2026 16:21
Copy link
Copy Markdown

@cursor cursor Bot left a comment

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 and found 1 potential issue.

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 5f9a9ff. Configure here.

@abelonogov-ld abelonogov-ld merged commit 275ab9f into main Apr 9, 2026
23 checks passed
@abelonogov-ld abelonogov-ld deleted the andrey/maui-dist-doc branch April 9, 2026 21:45
abelonogov-ld added a commit that referenced this pull request Apr 14, 2026
* main:
  chore: release main (#467)
  feat: Support 8 byte colors + non-linearity in hash (#466)
  chore: release main (#465)
  feat: Tracing API polishing + Distributed tracing Docs (#464)
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