Replace misleading IScopeObserver.setBreadcrumbs with clearBreadcrumbs
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 56/100
- Issue 類型
- 重構
- 描述清晰度
- 描述清楚
- 活躍度
- 冷清
- 技術堆疊
- java
研究方向
先從 IScopeObserver.java、ScopeObserverAdapter.java 和 Scope.java 開始,追蹤 observer 呼叫,然後檢查 PersistingScopeObserver.java 和受影響的測試。更新 issue 中指定的 API surface 和測試,讓清除使用 clearBreadcrumbs(),並確認 batching 和 scope 測試涵蓋新的行為,不再透過 setBreadcrumbs(emptyList()) 表達清除。
由索引模型根據 Issue 內容生成。
描述
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
- 主要語言
- Kotlin
- 星號
- 1.4k
- 分支
- 478
- 平均合併
- 2 天 20 小時
- 30 天內合併 PR
- 71
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
getsentry/sentry-java 的其他 Issue
-
Improvement Java Platform: Android Platform: Java
難度 2/5 1-3 小時 新手友好度 75/100
getsentry/sentry-java#6145 · 1 則留言 · 已指派 1 人 ·
-
Bug Java Platform: Android Platform: Java
難度 2/5 1-3 小時 新手友好度 78/100
getsentry/sentry-java#6138 · 1 則留言 ·
-
Feature Java Platform: Java Spans
難度 2/5 1-3 小時 新手友好度 68/100
getsentry/sentry-java#5984 · 1 則留言 ·
-
Android Task Traces
難度 2/5 1-3 小時 新手友好度 68/100
getsentry/sentry-java#5376 · 1 則留言 ·
-
Android Docs Errors
難度 2/5 1-3 小時 新手友好度 64/100
getsentry/sentry-java#5375 · 1 則留言 ·
查看 getsentry/sentry-java 的全部 Issue
相似的 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 75/100
AAswordman/Operit#1265 · 3 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 65/100
acristescu/OnlineGo#216 ·
-
enhancement
難度 2/5 1-3 小時 新手友好度 65/100
libre-tube/LibreTube#8803 ·
-
難度 2/5 1-3 小時 新手友好度 75/100
-
status: waiting-for-triage type: bug
難度 2/5 1-3 小時 新手友好度 65/100
spring-projects/spring-security#19781 ·