Commit 0e2482b
authored
feat: MAUI Network tracing 0.8.0 (#463)
## Summary
- **Network request tracing for .NET MAUI**: Adds `System.Net.Http`
Activity source to `LDTracer` so HTTP requests made from .NET are
automatically captured as spans. On iOS, native `urlSession`
instrumentation is disabled since tracing now happens on the .NET side.
On Android, `UseNativeHttpHandler` is set to `false` in the sample
project so `SocketsHttpHandler` emits Activity diagnostics.
- **Configurable instrumentation options**: Introduces
`InstrumentationOptions` (with `NetworkRequests` and `LaunchTimes`
toggles) on `ObservabilityOptions`, plumbed through the iOS (Swift) and
Android (Kotlin) native bridges so each instrumentation can be
individually enabled/disabled from the .NET layer.
- **Span-context-aware logging**: `LDObserve.RecordLog` now accepts an
optional `SpanContext?` parameter. When provided, its trace/span IDs are
forwarded to the native logger; otherwise the ambient `Activity.Current`
is used. The native logger is obtained via new `ObjcLogger` (iOS) and
`RealLogger` (Android) bridge classes, replacing the old `recordLog`
method on `ObservabilityBridge`.
- **New public APIs on `LDObserve`**: `RecordError(Exception)`,
`StartRootSpan(string)`, and `GetTracer()` (with no-op fallback before
init).
- **Android SDK**: `TracesApi.startSpan` now defaults `attributes` to
`Attributes.empty()`.
- **E2E example**: Android `ViewModel` demonstrates parent/child span
creation and cross-thread context propagation.
- **Version bump**: `LaunchDarkly.SessionReplay` 0.6.0 → 0.8.0.
<img width="1592" height="1740" alt="image"
src="https://github.com/user-attachments/assets/7f95d3e1-db90-4607-bf8d-48f0706b5716"
/>
## Changes by area
### .NET SDK (`mobile-dotnet/observability`)
- New `InstrumentationOptions` class with `NetworkRequests` and
`LaunchTimes` booleans (default `true`), added to
`ObservabilityOptions`.
- `ObservabilityPlugin` enables
`System.Net.Http.EnableActivityPropagation` when network request tracing
is on.
- `LDTracer` is no longer a singleton; accepts `serviceName` and
`networkRequests` params; conditionally subscribes to `System.Net.Http`
Activity source.
- New `ObservabilityService` consolidates all bridge calls, tracer
lifecycle, and native logger acquisition. Replaces deleted
`NativeObserve`.
- `LDObserve` is now a thin static facade over `ObservabilityService`;
safe to call before initialization (no-ops).
- `PluginOrchestrator` renamed properties to `ObservabilityService` /
`SessionReplayService`; calls `LDObserve.Initialize()` after native
start.
- Native bridge mappings (`LDNative.Android.cs`, `SRClient.iOS.cs`) pass
new instrumentation options through.
### Native bridges — iOS (Swift)
- `ObjcObservabilityOptions` adds `networkRequests` and `launchTimes`
properties.
- `ObservabilityBridge` disables `urlSession` instrumentation and makes
`launchTimes` configurable.
- New `ObjcLogger` class exposed via `LDObserveBridge.getObjcLogger()`.
- iOS binding `ApiDefinition.cs` updated with new properties and
`ObjcLogger` interface.
### Native bridges — Android (Kotlin)
- `LDObservabilityOptions` adds `launchTime` field; options classes
moved to `OptionsBridge.kt`.
- `ObservabilityBridge` reads `launchTime` from options instead of
hardcoding `true`; `recordLog` removed.
- New `RealLogger` wrapper around `KotlinLogger` for C# binding.
- `LDObserveBridgeAdapter` exposes `getLogger()`.
### Android SDK (`observability-android`)
- `TracesApi.startSpan` parameter `attributes` now defaults to
`Attributes.empty()`.
### E2E / Sample
- Android e2e `ViewModel` demonstrates parent-child span creation and
cross-thread context propagation.
- MAUI sample `MauiProgram.cs` uses the new `InstrumentationOptions`
API.
- MAUI sample `.csproj` sets `UseNativeHttpHandler=false` for Android to
enable `System.Net.Http` Activity diagnostics.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Touches cross-platform observability initialization and tracing
sources (including automatic `System.Net.Http` span capture), so
misconfiguration could change telemetry volume/correlation or miss spans
on iOS/Android.
>
> **Overview**
> Adds **automatic .NET MAUI HTTP request tracing** by extending
`LDTracer` to optionally subscribe to the `System.Net.Http` Activity
source and enabling `System.Net.Http.EnableActivityPropagation` when
configured.
>
> Introduces `InstrumentationOptions` on `ObservabilityOptions` (toggles
for `NetworkRequests` and `LaunchTimes`) and plumbs these through the
Android (Kotlin) and iOS (Swift + binding) native bridges; iOS disables
native `urlSession` tracing in favor of .NET-side tracing, and Android
bridge now respects a configurable `launchTime` flag.
>
> Hardens initialization by making `PluginOrchestrator` initialize only
once, updates samples/e2e to demonstrate cross-thread span context
propagation and config usage (including Android
`UseNativeHttpHandler=false`), and bumps `LaunchDarkly.SessionReplay`
package version to `0.8.0`.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
abda519. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 467105a commit 0e2482b
18 files changed
Lines changed: 89 additions & 16 deletions
File tree
- e2e/android/app/src/main/java/com/example/androidobservability
- sdk/@launchdarkly
- mobile-dotnet
- android/native/LDObserve/src/main/java/com/example/LDObserve
- macios
- LDObserve.MaciOS.Binding
- native/LDObserve/Sources
- observability
- bridge
- infra
- observe
- api
- plugin
- sample
- observability-android/lib/src/main/kotlin/com/launchdarkly/observability
- interfaces
- sdk
Lines changed: 24 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| 27 | + | |
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
| |||
83 | 86 | | |
84 | 87 | | |
85 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
86 | 106 | | |
87 | 107 | | |
88 | 108 | | |
| |||
97 | 117 | | |
98 | 118 | | |
99 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
100 | 124 | | |
101 | 125 | | |
102 | 126 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
| 87 | + | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| |||
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | | - | |
| 22 | + | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| 32 | + | |
30 | 33 | | |
31 | 34 | | |
32 | 35 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
33 | 39 | | |
34 | 40 | | |
35 | 41 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | | - | |
| 28 | + | |
| 29 | + | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| |||
0 commit comments