feat(android): Report app start reason on standalone app start transaction#5552
feat(android): Report app start reason on standalone app start transaction#5552buenaflor wants to merge 2 commits into
Conversation
d39e93a to
73d05fc
Compare
|
📲 Install BuildsAndroid
|
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| a416a65 | 295.53 ms | 373.74 ms | 78.21 ms |
| d15471f | 307.28 ms | 381.85 ms | 74.57 ms |
| 4c04bb8 | 350.71 ms | 413.63 ms | 62.92 ms |
| 9e60aca | 316.18 ms | 345.04 ms | 28.86 ms |
| 2124a46 | 319.19 ms | 415.04 ms | 95.85 ms |
| 46b442b | 321.41 ms | 339.30 ms | 17.89 ms |
| b193867 | 331.08 ms | 397.06 ms | 65.98 ms |
| b6702b0 | 395.86 ms | 409.98 ms | 14.12 ms |
| ed33deb | 312.34 ms | 369.71 ms | 57.37 ms |
| cf708bd | 434.73 ms | 502.96 ms | 68.22 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| a416a65 | 1.58 MiB | 2.12 MiB | 555.26 KiB |
| d15471f | 1.58 MiB | 2.13 MiB | 559.54 KiB |
| 4c04bb8 | 0 B | 0 B | 0 B |
| 9e60aca | 0 B | 0 B | 0 B |
| 2124a46 | 1.58 MiB | 2.12 MiB | 551.51 KiB |
| 46b442b | 0 B | 0 B | 0 B |
| b193867 | 1.58 MiB | 2.19 MiB | 620.00 KiB |
| b6702b0 | 1.58 MiB | 2.12 MiB | 551.79 KiB |
| ed33deb | 1.58 MiB | 2.13 MiB | 559.52 KiB |
| cf708bd | 1.58 MiB | 2.11 MiB | 539.71 KiB |
There was a problem hiding this comment.
Pull request overview
Adds Android 15+ (API 35) enrichment to standalone app start tracing by attaching a stable, low-cardinality process start “reason” derived from ApplicationStartInfo.getReason() as trace data on the standalone app.start transaction.
Changes:
- Add
AppStartMetrics.getAppStartReason()to mapApplicationStartInfostart reasons to stable lowercase strings (ornullwhen unavailable/unmapped). - Attach
app.start.reasonto the standaloneapp.starttransaction for both foreground (onActivityCreated) and headless (onHeadlessAppStart) standalone paths. - Add/extend unit tests to cover mapping behavior and verify trace data presence/absence on standalone transactions.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java | Adds getAppStartReason() mapping logic and a test-only setter for cached ApplicationStartInfo. |
| sentry-android-core/src/main/java/io/sentry/android/core/ActivityLifecycleIntegration.java | Writes app.start.reason trace data onto standalone app.start transactions in both foreground and headless flows. |
| sentry-android-core/src/test/java/io/sentry/android/core/performance/AppStartMetricsTestApi35.kt | Adds API 35 tests for reason→string mapping and null cases. |
| sentry-android-core/src/test/java/io/sentry/android/core/ActivityLifecycleIntegrationTest.kt | Adds tests asserting app.start.reason is present/absent on standalone transactions (foreground and headless). |
| sentry-android-core/api/sentry-android-core.api | Updates API dump for the new AppStartMetrics methods. |
| CHANGELOG.md | Documents the new app.start.reason data on API 35+ for standalone app start transactions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ction Read ApplicationStartInfo.getReason() (API 35+) and attach it as app.start.reason trace data on the standalone app.start transaction in both the foreground and headless paths. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
73d05fc to
2823497
Compare
Advertise that standalone app start tracing is active by adding a StandaloneAppStart marker to the SDK metadata integrations when the feature is enabled. Internal SDK metadata only. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
990e4c6 to
0b0dd48
Compare
|
|
||
| if (performanceEnabled && this.options.isEnableStandaloneAppStartTracing()) { | ||
| AppStartMetrics.getInstance().setHeadlessAppStartListener(this::onHeadlessAppStart); | ||
| addIntegrationToSdkVersion("StandaloneAppStart"); |
There was a problem hiding this comment.
needed for tracking in looker
runningcode
left a comment
There was a problem hiding this comment.
Looks great! I feel a bit mixed about the added ActivityLifecycleIntegrationTest.kt since we're just setting the value and then getting it.
| - Emits a transaction named `App Start` with op `app.start`, carrying the existing app start measurements and phase spans (`process.load`, `contentprovider.load`, `application.load`, activity lifecycle spans) as direct children of the root | ||
| - The standalone transaction shares the same `traceId` as the first `ui.load` activity transaction so they remain linked in the trace view | ||
| - Also covers non-activity starts (broadcast receivers, services, content providers) | ||
| - On Android 15+ (API 35), the standalone transaction reports why the OS started the process via `app.vitals.start.reason` trace data (e.g. `launcher`, `broadcast`, `service`, `content_provider`), derived from `ApplicationStartInfo.getReason()` ([#5552](https://github.com/getsentry/sentry-java/pull/5552)) |
There was a problem hiding this comment.
maybe worth mentioning that customers can search/group by this property in trace viewer? (they can, right?)
📜 Description
Reports why the OS started the process on the standalone app start transaction, using
ApplicationStartInfo.getReason()(Android 15 / API 35+).AppStartMetrics.getAppStartReason(), which maps the already-cachedApplicationStartInforeason to a stable lowercase string (launcher,launcher_recents,start_activity,broadcast,service,content_provider,job,alarm,push,backup,boot_complete,other). Returnsnullon API < 35, when no start info was resolved, or for an unmapped value.app.vitals.start.reasontrace data on the standaloneapp.starttransaction in both paths: foreground/activity (onActivityCreated) and headless/non-activity (onHeadlessAppStart).StandaloneAppStartmarker in the SDK metadataintegrationswhen the feature is enabled (internal only, no changelog) so we can tell from events that standalone app start tracing was active.Only standalone app start transactions are affected; this rides the existing
enableStandaloneAppStartTracingopt-in and adds no new option.💡 Motivation and Context
Builds on standalone app start tracing (#5342). The reason is a high-value dimension for standalone starts: it distinguishes a real user launch (
launcher/start_activity) from headless starts (broadcast,service,content_provider,job, …) — exactly the disambiguation the headless app start path was built for. The reason (why the process started) is orthogonal to cold/warm (getStartType()), so both are reported.ApplicationStartInfois already cached inAppStartMetricsfrom the standalone work, so this only reads one additional field (getReason()) off the same object — no extra system calls.💚 How did you test it?
Unit tests in
sentry-android-core:AppStartMetricsTestApi35: reason → string mapping (API 35),nullwhen no start info,nullfor an unmapped reason value.ActivityLifecycleIntegrationTest:app.vitals.start.reasonpresent on the foreground standalone transaction (API 35), absent when unavailable, and present on the headless standalone transaction.Note: the headless-vs-foreground detection in
PerformanceAndroidEventProcessorkeys off the absence ofapp.vitals.start.screen; the new distinctapp.vitals.start.reasonkey does not affect it (existing tests still pass).📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps