getsentry / getsentry/sentry-java

Run the Integration.register() loop off the main thread (two-phase init)

Offen
#5,704 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Android Improvement Platform: Java
Vorherrschende Sprache
Kotlin
Sterne
1.4k
Forks
478
Ø Merge
2 T. 23 Std.
Gemergte PRs (30 T.)
67

Beschreibung

## Problem

`Sentry.init` registers all integrations synchronously on the calling thread (`sentry/src/main/java/io/sentry/Sentry.java:374-385`) — the main thread under auto-init. With ~17 default Android integrations this is the biggest remaining *block* of main-thread init work once the per-integration items (NDK etc.) are fixed.

## Proposal

Keep a minimal synchronous core — options, scopes, `SentryClient` binding, `UncaughtExceptionHandlerIntegration` — and submit the rest of the registration loop to `options.getExecutorService()`, with an opt-in marker for integrations that genuinely need the main thread (`AppLifecycleIntegration` already self-posts when off-main).

`Sentry.captureX` immediately after `init()` keeps working: the client is bound synchronously and events queue on the transport.

## Constraints

* The deliberate startup-crash blocking flush (`sentry-android-core/.../SendCachedEnvelopeIntegration.java:151-161`) must still block `init()` — needs an explicit carve-out.
* Integration ordering guarantees (NDK before outbox watcher, AppLifecycle before ANR, ANR before Replay — see comments in `AndroidOptionsInitializer.installDefaultIntegrations`) must be preserved. The single-threaded executor keeps submission order, but mixed sync/async registration could break it; audit each.
* Session auto-start + `isForegroundImportance()` at the end of `SentryAndroid.init` (`SentryAndroid.java:184-203`) depend on integration state (LifecycleWatcher) — decide whether they move too.

Concrete follow-up to getsentry/sentry-java#5475 ("Move more init code async").

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Start with the registration loop in sentry/src/main/java/io/sentry/Sentry.java:374-385 and the ordering comments in AndroidOptionsInitializer.installDefaultIntegrations. Then inspect SendCachedEnvelopeIntegration.java:151-161 and SentryAndroid.java:184-203. Done means defining the synchronous and executor-backed phases while preserving startup-crash flushing, integration ordering, and session or foreground-state behavior.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
android, java
Bereich
mobile-dev, performance
Issue-Typ
Refactoring
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.