1398281322-a11y/java-backend-guardrails / skills/java-backend-guardrails/observability
observability
VerifiedUse when adding tracing, metrics, 链路追踪, TraceId, 慢接口排查, 全链路压测, or production incident workflow. Skip when the task is greenfield CRUD with no performance or incident context.
可观测 / 线上排查
When to Invoke
慢接口、偶发失败、要加监控、事故复盘、全链路压测。高级面常问「线上 RT 高你怎么查」。
When NOT
还没写业务就上完整 APM 平台当任务本身。先有 TraceId 和关键指标。
风险(面试考点)
没有 同一 TraceId 穿网关→服务→MQ→DB,日志对不上。指标只看 CPU 会误判(可能是锁、GC、慢 SQL、依赖超时)。压测不带数据隔离会打脏生产。
排查顺序(固定):
- 是全站还是单接口、从何时开始
- 错误率 / RT / QPS 哪个变了
- 依赖 RT(DB、Redis、Feign、MQ 积压)
- 实例是否均衡、GC、线程池拒绝
- 单请求日志(TraceId)看卡在哪一段
不要先 dump 堆。
方案选型(轻量优先)
| 层 | 默认 |
|---|---|
| 日志 | 每条带 traceId、userId、orderNo |
| 指标 | QPS、RT P99、错误率、线程池、DB 连接池、MQ 积压 |
| 追踪 | 网关生成 TraceId,Feign/MQ 透传 |
| 告警 | 错误率、P99、积压、拒绝次数,不是 CPU 单指标 |
默认方案
MDC 放 TraceId;HTTP 头 X-Trace-Id;RocketMQ 属性同样透传。慢 SQL 阈值 1s 先打日志。核心接口有黄金指标看板。
压测:影子表/影子标,或预发全量。生产全链路压测必须能识别压测流量并隔离写。
反例
错误:RT 高先重启再 dump。 正确:按上面 1–5。
错误:日志没有业务单号,只能搜时间。
正确:orderNo 可检索。
错误:只监控机器 CPU。 正确:先看接口和依赖。
验证
- 任意失败请求能用 TraceId 串起网关到 DB。
- 人为把从库打慢,看板能显示是 DB 不是 JVM。
评审清单
- 写路径日志有业务键 + TraceId
- 核心接口有 QPS/RT/错误
- 排查顺序不是先重启
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| planning-and-task-breakdownaddyosmani/agent-skillsBreaks work into ordered tasks. Use when you have a spec or clear requirements and need to break work into implementable tasks. Use when a task feels too large to start, when you need to estimate scope, or when parallel work is possible. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |
| screenpipethedotmack/claude-memSearch screen and audio history recorded by Screenpipe and optionally save selected context into claude-mem. Use when the user asks to recall desktop activity, a meeting, or something seen in another app through Screenpipe. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |
| contact-widgetnexu-io/open-designSelf-contained floating chat widget with welcome screen, social links, meeting button, and message input. Single HTML file, zero dependencies. | Stars: 108k | Updated | Claude CodeCodex | Verified | Install |
| meeting-notesnexu-io/open-designMeeting notes page — title bar with attendees, agenda checklist, decisions block, action items table with owners + dates, and a "next meeting" footer. Use when the brief mentions "meeting notes", "minutes", "1:1 notes", "all-hands recap", or "会议纪要". | Stars: 108k | Updated | Claude CodeCodex | Verified | Install |