Replace misleading IScopeObserver.setBreadcrumbs with clearBreadcrumbs
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 56/100
- Tipo di issue
- Refactoring
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- java
- Ambito
- backend-api-design
Direzione di ricerca
Inizia da IScopeObserver.java, ScopeObserverAdapter.java e Scope.java per tracciare le chiamate dell’observer, quindi esamina PersistingScopeObserver.java e i test interessati. Aggiorna la superficie dell’API e i test indicati nell’issue in modo che la cancellazione utilizzi clearBreadcrumbs(), e verifica che i test di batching e di scope coprano il nuovo comportamento e non esprimano più la cancellazione tramite setBreadcrumbs(emptyList()).
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
IScopeObserver.setBreadcrumbs(Collection<Breadcrumb>) reads like a bulk setter — "replace the observed breadcrumbs with this collection" — but that isn't its contract. Its real meaning is "the breadcrumbs were cleared", encoded as "the collection I passed you happens to be empty."
PersistingScopeObserver is the only implementation that does anything, and it never looks at the elements:
public void setBreadcrumbs(@NotNull Collection<Breadcrumb> breadcrumbs) {
if (breadcrumbs.isEmpty()) {
// ...enqueue a clear...
}
// non-empty: silently do nothing
}
Why this is a problem
- The parameter is a boolean in disguise. The only thing read off the collection is
isEmpty(). A non-empty argument is silently ignored, so anyone who takes the name at face value and writes a bulk-replace implements something the SDK never drives that way. - It hides a real race.
Scope.clearBreadcrumbs()clears the live queue and then hands that same live queue to the observers. If another thread adds a breadcrumb between theclear()and the observer loop, the collection is no longer empty,PersistingScopeObserverdoes nothing, and the pre-clear breadcrumbs survive on disk — cleared in memory, not cleared in the scope cache. The signal is carried by mutable state observed after the fact instead of by the call itself. Narrow in practice (clearBreadcrumbs()isn't on a hot path), and the symptom is stale breadcrumbs on the next ANR/crash report rather than anything immediately user-visible. - It's called constantly for nothing.
Scope.addBreadcrumbinvokes bothaddBreadcrumbandsetBreadcrumbson every observer for every breadcrumb. The second call can only ever be a no-op (the collection just had an element added), so we pay an extra virtual call per observer per breadcrumb on a hot path — and it's why the batching work in getsentry/sentry-java#5714 needed extra care around clear ordering. - It's inconsistent with the rest of the interface. Attachments already do this correctly:
addAttachment/clearAttachments. Breadcrumbs are the odd one out. - The name collides with a genuine setter.
SentryBaseEvent.setBreadcrumbs(List)really does replace the list, so the same name means two different things depending on the receiver.
Proposed change
- Add
clearBreadcrumbs()toIScopeObserverandScopeObserverAdapter. Scope.clearBreadcrumbs()callsobserver.clearBreadcrumbs();Scope.addBreadcrumbdrops itsobserver.setBreadcrumbs(...)call entirely.PersistingScopeObserver.setBreadcrumbsbecomesclearBreadcrumbs(), unconditionally enqueueing the clear marker — which also removes the race in (2).- Remove
setBreadcrumbsfromIScopeObserver. It's public API and not@ApiStatus.Internal, hence filing this against the 9.0 major. - Fix
IScopeObserver's javadoc, which claims all methods aredefault— none of them are. - Update
ScopeTest,PersistingScopeObserverTest, andPersistingScopeObserverBatchingTest, which currently express "clear" assetBreadcrumbs(emptyList()).
Notes
NdkScopeObserver implements addBreadcrumb but not setBreadcrumbs, so native breadcrumbs are never cleared today. A clearBreadcrumbs() on the interface makes that gap visible; there's no corresponding entry point on INativeScope, so closing it would be follow-up work.
Affected files: sentry/src/main/java/io/sentry/IScopeObserver.java, ScopeObserverAdapter.java, Scope.java, cache/PersistingScopeObserver.java, sentry/api/sentry.api
- Lingua principale
- Kotlin
- Stelle
- 1.4k
- Fork
- 478
- Merge medio
- 2g 20h
- PR unite (30g)
- 71
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di getsentry/sentry-java
-
Improvement Java Platform: Android Platform: Java
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
getsentry/sentry-java#6145 · 1 commento · 1 assegnatario ·
-
Bug Java Platform: Android Platform: Java
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
getsentry/sentry-java#6138 · 1 commento ·
-
Feature Java Platform: Java Spans
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
getsentry/sentry-java#5984 · 1 commento ·
-
Android Task Traces
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
getsentry/sentry-java#5376 · 1 commento ·
-
Android Docs Errors
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
getsentry/sentry-java#5375 · 1 commento ·
Tutte le issue di getsentry/sentry-java
Issue simili
-
[Bug] 统计页面无法重置token和汇率 Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
AAswordman/Operit#1265 · 3 commenti ·
-
Tambahkan bahasa Indonesia Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
acristescu/OnlineGo#216 ·
-
Remove custom segment colors Apertaenhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
libre-tube/LibreTube#8803 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
status: waiting-for-triage type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
spring-projects/spring-security#19781 ·