Replace misleading IScopeObserver.setBreadcrumbs with clearBreadcrumbs
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 56/100
- Loại issue
- Tái cấu trúc
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- java
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
Bắt đầu với IScopeObserver.java, ScopeObserverAdapter.java và Scope.java để lần theo các lệnh gọi observer, sau đó kiểm tra PersistingScopeObserver.java và các test bị ảnh hưởng. Cập nhật API surface và các test được nêu trong issue để việc xóa sử dụng clearBreadcrumbs(), đồng thời xác minh rằng các test batching và scope bao quát hành vi mới và không còn thể hiện việc xóa thông qua setBreadcrumbs(emptyList()).
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Kotlin
- Star
- 1.4k
- Fork
- 478
- Merge trung bình
- 3 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 70
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của getsentry/sentry-java
-
Bug Java Platform: Java
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
getsentry/sentry-java#6138 · 1 bình luận ·
-
Feature Java Platform: Java Spans
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
getsentry/sentry-java#5984 · 1 bình luận ·
-
Android Task Traces
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
getsentry/sentry-java#5376 · 1 bình luận ·
-
Android Docs Errors
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
getsentry/sentry-java#5375 · 1 bình luận ·
-
Android good first issue Task User Feedbacks
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 68/100
getsentry/sentry-java#5354 · 1 bình luận ·
Tất cả issue của getsentry/sentry-java
Issue tương tự
-
Icon Requests Đang mởsupported
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
LawnchairLauncher/lawnicons#4100 ·
-
cr:missing-repro cr:platform:android platform:android repro-provided
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
software-mansion/react-native-screens#4699 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Good First Issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
ankidroid/Anki-Android#21942 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
libre-tube/LibreTube#8781 · 1 bình luận ·