Skip to content

[Mono.Android] Add runtime startup tracing API - #13779

Draft
simonrozsival wants to merge 2 commits into
mainfrom
simonrozsival-agent-observability
Draft

simonrozsival wants to merge 2 commits into
mainfrom
simonrozsival-agent-observability

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Android tooling needs a way to observe managed startup and Activity lifecycle without requiring an exporter or adding an OpenTelemetry SDK dependency to the runtime. This change adds an opt-in runtime tracing API that exposes those spans through ActivitySource, retains startup phase timing until a listener is registered, and replays the original span hierarchy to late consumers. It also documents consumer setup and adds focused on-device coverage.

Startup tracing is disabled by default. The startup root covers managed initialization rather than earlier process/native startup; Activity lifecycle spans describe framework notifications, not the full duration of overridden Activity methods.

Each managed GC bridge pass emits android.runtime.gc_bridge.process (component, cross-reference, and collected counts) after processing completes. Fine-grained interop spans use a separate Microsoft.Android.Runtime.Interop source, so listening to it is the opt-in for higher-volume data: per-class register_natives, create_peer, and type map cache misses in both directions. ActivitySource.StartActivity returns null without a sampling listener, and the JNI-dependent create_peer class-name tag is gated on IsAllDataRequested. Interop spans are not buffered during startup, and their overhead with a listener attached has not been measured.

Validation:

  • make prepare CONFIGURATION=Debug && make leeroy CONFIGURATION=Debug MSBUILD_ARGS='-m:4 -p:EnableSourceLink=false -p:EnableSourceControlManagerQueries=false' — passed.
  • ./dotnet-local.sh build -t:Install -c Debug -p:Device=emulator-5588 -p:IncludeCategories=AndroidTelemetry -p:AndroidTelemetryStartupTracing=true tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj — passed.
  • (cd tests/Mono.Android-Tests/Mono.Android-Tests && ../../../dotnet-local.sh test Mono.Android.NET-Tests.csproj --no-build -c Debug --report-trx --results-directory ../../../bin/TestDebug/TestResults -p:Device=emulator-5588 -p:IncludeCategories=AndroidTelemetry -p:AndroidTelemetryStartupTracing=true) — passed: 2 tests, 0 failures.
  • After adding GC bridge and interop spans: make leeroy, then the install and test commands above with --device emulator-5588 and without AndroidTelemetryStartupTracing — passed: 4 tests, 0 failures.

Expose opt-in startup and Activity lifecycle spans through an in-process API so tooling can observe Android app behavior without adding an exporter dependency. Startup spans are retained until a listener is registered, preserving phase timing and parentage for late consumers.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Emit `android.runtime.gc_bridge.process` from the `Microsoft.Android.Runtime`
source after each managed GC bridge pass, and add a separate fine-grained
`Microsoft.Android.Runtime.Interop` source for per-class native registration,
peer creation, and type map cache misses in both directions.

Traces have no levels, so the separate source is the opt-in for
higher-volume interop data. Costly tags (a JNI call for the Java class name
in `create_peer`) are gated on `IsAllDataRequested`.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.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.

1 participant