Skip to content

feat: MAUI trace log correlation#461

Merged
abelonogov-ld merged 14 commits intomainfrom
andrey/trace-log-correlation
Apr 9, 2026
Merged

feat: MAUI trace log correlation#461
abelonogov-ld merged 14 commits intomainfrom
andrey/trace-log-correlation

Conversation

@abelonogov-ld
Copy link
Copy Markdown
Contributor

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

Summary

  • Introduce ObservabilityService — a new internal service class that consolidates all native bridge calls (logging, errors, metrics, tracing) and owns the LDTracer lifecycle. Replaces the deleted NativeObserve class and eliminates scattered #if IOS / ANDROID directives from LDObserve.
  • Add trace-log correlationRecordLog now accepts an optional SpanContext parameter, forwarding traceId/spanId to the native logger. Falls back to the ambient Activity.Current when no explicit context is provided.
  • Expose RealLogger on Android and ObjcLogger on iOS — new native wrappers obtained via LDObserveBridgeAdapter.getLogger() / LDObserveBridge.getObjcLogger(), replacing the old recordLog method on ObservabilityBridge.
  • Rename NativeSessionReplaySessionReplayService and NativeObserveObservabilityService throughout the plugin layer for consistent naming.
  • Make LDTracer non-singleton — constructor now takes serviceName, created and owned by ObservabilityService during initialization.
  • Simplify LDObserve static facade — all methods delegate to ObservabilityService via a volatile reference; safe no-op behavior before initialization. Add StartRootSpan, RecordError(Exception) overload.
  • Extract option classesLDObservabilityOptions, LDPrivacyOptions, LDSessionReplayOptions moved from ObservabilityBridge.kt into a dedicated OptionsBridge.kt.
  • Update sample app — add "Log with Context" button demonstrating span-context-attached logging; use RecordError(Exception) overload; route span creation through LDObserve.StartRootSpan.

Test plan

  • Build Android and iOS targets to verify native bindings compile (RealLogger, ObjcLogger)
  • Run sample app on Android emulator — tap "Trigger Log", "Log with Context", "Trigger Error", "Sequential Spans", "Custom Span" and verify data reaches the backend
  • Run sample app on iOS simulator — same smoke test
  • Verify logs sent via "Log with Context" carry the expected traceId/spanId in the backend
  • Confirm LDObserve methods are no-ops before plugin registration (no crashes)
  • Check that RecordError(Exception) sends both message and full stack trace

Note

Medium Risk
Medium risk due to refactoring the observability facade and plugin initialization flow, plus new native bindings (ObjcLogger/RealLogger) that must compile and behave consistently on both iOS and Android.

Overview
Adds trace-log correlation and centralizes native observability calls. Introduces an internal ObservabilityService that owns LDTracer lifecycle and routes logs/errors/metrics/spans through platform-native bridges, replacing the deleted NativeObserve and removing per-call #if IOS/ANDROID branching from LDObserve.

LDObserve.RecordLog now accepts an optional OpenTelemetry SpanContext (falling back to Activity.Current) and forwards traceId/spanId to a new native logger interface; iOS binding adds ObjcLogger/getObjcLogger, Android adds RealLogger/getLogger and moves Kotlin option DTOs into OptionsBridge.kt.

Plugin wiring is updated to use ObservabilityService/SessionReplayService (renamed from NativeSessionReplay), with PluginOrchestrator initializing LDNative and then calling LDObserve.Initialize when observability is enabled. Sample app is updated to demonstrate "Log with Context", RecordError(Exception), and StartRootSpan usage.

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

@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 2 times, most recently from 2bd87dd to 6e27d9c Compare April 8, 2026 00:58
- 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.
@abelonogov-ld abelonogov-ld force-pushed the andrey/trace-log-correlation branch from e47e8aa to c39ec78 Compare April 9, 2026 00:51
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 c39ec78. Configure here.

@abelonogov-ld abelonogov-ld changed the title WIP feat: MAUI trace log correlation feat: MAUI trace log correlation Apr 9, 2026
@abelonogov-ld abelonogov-ld merged commit 467105a into main Apr 9, 2026
23 checks passed
@abelonogov-ld abelonogov-ld deleted the andrey/trace-log-correlation branch April 9, 2026 14:48
abelonogov-ld added a commit that referenced this pull request Apr 9, 2026
* andrey/maui-network:
  feat: MAUI trace log correlation (#461)
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