Skip to content

WIP feat: MAUI trace log correlation#461

Open
abelonogov-ld wants to merge 12 commits intomainfrom
andrey/trace-log-correlation
Open

WIP feat: MAUI trace log correlation#461
abelonogov-ld wants to merge 12 commits intomainfrom
andrey/trace-log-correlation

Conversation

@abelonogov-ld
Copy link
Copy Markdown
Contributor

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

Summary

How did you test this change?

Are there any deployment considerations?


Note

Medium Risk
Moderate risk because it refactors core observability initialization and replaces the tracing/log export path (including new native bindings), which could affect telemetry emission or span/log correlation across iOS/Android.

Overview
Enables trace-log correlation by routing LDObserve.RecordLog through a new ObservabilityService that can attach traceId/spanId from either Activity.Current or an explicit ActivityContext.

Replaces the previous OpenTelemetry TracerProvider/LDTraceExporter pipeline with a System.Diagnostics.ActivitySource + ActivityListener in LDTracer, exporting stopped activities to the native tracer via TraceBuilderAdapter, and exposes new LDObserve APIs (GetActivitySource, StartActiveSpan, StartRootSpan).

Adds native logger bindings on both platforms (getLogger/RealLogger on Android; ObjcLogger + getObjcLogger on iOS) and refactors plugin orchestration and hooks to use ObservabilityService/SessionReplayService (renaming/removing old NativeObserve/NativeSessionReplay), with the MAUI sample updated to exercise the new span/log context flow.

Reviewed by Cursor Bugbot for commit e47e8aa. 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.
@abelonogov-ld abelonogov-ld requested a review from a team as a code owner April 7, 2026 23:01
@abelonogov-ld abelonogov-ld changed the title feat: MAUI trace log correlation WIP feat: MAUI trace log correlation Apr 7, 2026
@abelonogov-ld abelonogov-ld force-pushed the andrey/trace-log-correlation branch from 2f27654 to 2bd87dd Compare April 7, 2026 23:46
- 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.
* main:
  feat: allow attach span context to logs (#460)
@abelonogov-ld abelonogov-ld force-pushed the andrey/trace-log-correlation branch from 2bd87dd to 6e27d9c Compare April 8, 2026 00:58
- 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.
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 e47e8aa. Configure here.

{
#if ANDROID
private static readonly LDObserveAndroid.ObservabilityBridge _androidBridge = new();
#endif
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Volatile write before initialization causes unsafe publication

Medium Severity

In LDObserve.Initialize, _service = service (a volatile write) happens before service.Initialize(). The volatile write acts as a release fence for prior stores only, but the writes to _tracer and _nativeLogger inside Initialize() happen after the volatile write, so they aren't covered by it. Another thread reading _service via the volatile field could see a non-null reference whose internal fields haven't been published yet. Swapping the two lines — calling service.Initialize() first, then assigning _service — ensures the volatile write publishes the fully-initialized object.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e47e8aa. Configure here.

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.

1 participant