[P2] `QueryClient` distributed-tracing observability in `BaseDataService`
维护者通常 1 天内回复
@MajorLift 已经在做这个了。
开始于 2026年9月21日。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 50/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- typescript
调研方向
从 packages/base-data-service/src/BaseDataService.ts 开始,追踪其内部 QueryClient 的创建和使用方式。评估 getter 和 constructor-hook 选项,然后验证下游的 queryCache.subscribe wiring 能够观察 cache 和 request 的生命周期,同时不改变 UI surface、OmitKeyof 行为、messenger contract 或 proxy queryFn 语义。
由索引模型根据 Issue 内容生成。
描述
Parent Epic: None (standalone)
File: packages/base-data-service/src/BaseDataService.ts
Size: S | Hours: 2–4
Problem
Option A's proxy model (TanStack Query QueryClient in the background process, proxy queryFn in the UI) intentionally hides the cache, dedupe, retry, fetch, and sync chain from UI-perceived latency tracing. The distributed-tracing wrappers in metamask-extension#39891 give us the call boundaries (useQuery → submitRequestToBackground → messenger → BaseDataService action → response). Inside the opaque region, every interesting decision is invisible:
- Cache hit vs. miss. Most data service calls don't make a network request. Auto-instrumented fetch spans see zero. The query looks "slow" with no attribution.
- In-flight dedupe. N concurrent observers collapse to one fetch. The fetch span doesn't know N.
- Cockatiel retry sequences. A single logical "fetch this" can produce 0, 1, or many HTTP requests. Auto-spans see them as unrelated. Backoff intervals are invisible.
- Circuit breaker state. When open, no fetch happens. The query fails or returns cached data with no auto-span at all.
- Cache sync to UI.
setData → cacheUpdated event → Port.postMessage → UI hydrateis the post-fetch synchronization cost. None of it surfaces as a span. - Trigger attribution. Poll interval, user invalidation, observer subscribe, and WebSocket invalidation are all identical from the network's view.
Three Option A tradeoffs documented in decisions#131 currently depend on observability that doesn't exist:
- Per-screen
staleTime. Validating that the service-side workarounds hold in production requires distinguishing fetches from cache serves. refetchOnMount/refetchOnWindowFocuscollapse. Measuring whether concurrent queries amplify messenger volume or are absorbed by backgroundstaleTime.- Split-process staleness indirection. Correlating UI proxy calls with background fetches.
Without this visibility, the tradeoffs are theoretical. With it, they're verifiable.
Solution
Add a sanctioned extension point to BaseDataService that exposes the internal QueryClient for read-only observability subscriptions. Two variants; preference is maintainer's call:
- Public getter.
get queryClient(): QueryClient - Constructor callback.
onCreate?: (qc: QueryClient) => void
Either is ~3 lines in core. Downstream clients attach their own instrumentation externally (e.g. qc.getQueryCache().subscribe(emitSpan) plus Cockatiel onRetry / onBreak handlers in extension's Sentry init, ~50 lines). The full span chain becomes stitchable end-to-end:
useQuery → submitRequestToBackground (span) → messenger (span) →
[BaseDataService.fetchQuery — cache miss, observerAdded → fetching →
Cockatiel attempt 1 → fetch (auto, child of rpc.handler) → 503 →
backoff 200ms → fetch (auto) → 200 → setData → success] →
cacheUpdated → port → UI hydrate
Acceptance Criteria
-
BaseDataServiceexposes either a publicqueryClientgetter or anonCreateconstructor hook (maintainer's choice). - Downstream
queryCache.subscribe(...)wiring composes cleanly from a client-side Sentry init file. A prototype in the extension repo demonstrates the full stack trace fromuseQuerythrough retry through success. - No new UI-facing surface.
- No change to
OmitKeyoftype erasure. - No change to messenger contract.
- No change to proxy
queryFnsemantics.
Labels
area-data-service, area-observability
Dependencies
Related: #8530, #8531 (orthogonal — same epic scope but different surface; not blocking).
Depends on: none.
Dependents: none.
- 主要语言
- TypeScript
- 星标
- 424
- 派生
- 311
- 平均合并
- 1 天 8 小时
- 30 天内合并 PR
- 446
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
MetaMask/core 的其他 Issue
-
EIP-1898 object selectors fail before downstream RPC in eth-json-rpc-middleware 26.0.0可能已有人在做 @debojyoti10CC 于 5 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
CI: "Validate changelog diffs" job fails on every fork-sourced pull request可能已有人在做 @Roxen-AS 于 37 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
platform-api-docs: `scan` strategy misses ESM-only packages, which ship `.d.ts` rather than `.d.cts`可能已有人在做 @gaohan1994 于 38 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
[utils] Replace the `uuid` dependency with `crypto.randomUUID()`可能已有人在做 @avantikonde 于 51 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
MetaMask/core#10210 · 1 个 reaction ·
维护者通常 1 天内回复
-
[utils] `toWei` accepts fractional wei and returns wrong values可能已有人在做 @Roxen-AS 于 37 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
相似的 Issue
-
Flaky test: selecting a portion just after inserting it can also match its Change and Delete buttons未关闭ready-for-agent
难度 2/5 1-3 小时 新手友好度 84/100
linagora/dcs-onlyoffice#172 ·
-
bug follow-up
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
nightly-tests
难度 2/5 1-3 小时 新手友好度 68/100
BlackBeltTechnology/pi-agent-dashboard#1226 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
danielmiessler/LifeOS#3028 ·
维护者通常 5 天内回复
-
execute_sql cannot create a SQLite trigger or a PostgreSQL BEGIN ATOMIC function: the statement is cut at the semicolons inside its body可能已有人在做 @goranai 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复