Replace misleading IScopeObserver.setBreadcrumbs with clearBreadcrumbs
维护者通常 1 天内回复
还没有人认领这个 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 天 15 小时
- 30 天内合并 PR
- 65
环境准备
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
getsentry/sentry-java 的其他 Issue
-
Platform: Java
难度 2/5 半天 新手友好度 76/100
getsentry/sentry-java#6161 · 1 条评论 ·
维护者通常 1 天内回复
-
Bug Java Platform: Android Platform: Java
难度 2/5 1-3 小时 新手友好度 78/100
getsentry/sentry-java#6138 · 1 条评论 ·
维护者通常 1 天内回复
-
Feature Java Platform: Java Spans
难度 2/5 1-3 小时 新手友好度 68/100
getsentry/sentry-java#5984 · 1 条评论 ·
维护者通常 1 天内回复
-
Android Task Traces
难度 2/5 1-3 小时 新手友好度 68/100
getsentry/sentry-java#5376 · 1 条评论 ·
维护者通常 1 天内回复
-
Android Docs Errors
难度 2/5 1-3 小时 新手友好度 64/100
getsentry/sentry-java#5375 · 1 条评论 ·
维护者通常 1 天内回复
查看 getsentry/sentry-java 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
block/artifact-swap#176 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
librepods-org/librepods#802 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
mrmans0n/asyncresult#102 ·
维护者通常 2 天内回复
-
follow-up
难度 2/5 1-3 小时 新手友好度 88/100
yschimke/homeassistant-remotecompose#680 ·
维护者通常 1 天内回复
-
:wave: team-triage a:chore in:isolated-projects in:kotlin-dsl
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复