observability

A set of rules for adding logs, measurements, request traces, and alerts to software systems. It explains how to record useful context, track service health, and follow a request across services.

In plain words
What is it for?
Use it when designing logging, service-health dashboards, alert thresholds, and OpenTelemetry tracing. It covers request rates, errors, latency, resource use, queues, database calls, and cross-service requests.
Why use it?
It helps developers find where failures occur, estimate their likely cause, and see whether a service is meeting its reliability targets. It also sets rules for protecting private data in logs.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/mywand/cusrsor-do-it/observability
Clone the repo
git clone --depth 1 https://github.com/mywand/cusrsor-do-it

Made for: Cursor.

Per session 13 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,732 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00013 $0.01732
Opus 5 $0.00006 $0.00866
Sonnet 5 $0.00003 $0.00346
Haiku 4.5 $0.00001 $0.00173

Measured 2d ago against content hash ccb93c0831fc, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

observability scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/tools/observability.mdc · 135 lines

How it starts

The opening of the file, as written. The whole thing — 135 lines — stays where its author put it; the contents beside it link to each section on GitHub.

最近更新: 2025-09-18

Observability Guide

1. 目标 (Goals)

  • 快速定位:问题发生 -> 5 分钟内能知道范围与根因候选。
  • 量化健康:核心指标仪表板实时反映 SLA 状态。
  • 可回放:关键业务路径具备足够上下文与追踪链路。

2. 三大支柱

支柱 作用 关键要素
Logs 定性分析 结构化 / 关键字段 / 采样策略
Metrics 定量趋势 标签维度 / 聚合 / 阈值报警
Traces 跨服务调用链 span 层级 / 耗时 / 错误传播

3. 日志 (Logging)

  • 结构化:JSON(字段:ts, level, traceId, spanId, userId, action, result, costMs, errorType)。
  • 分类:访问日志 / 业务日志 / 安全审计 / 异常日志 分开存储或打标签。
  • 采样:高 QPS 服务对 INFO 级别采样;错误级别全量。
  • 隐私:脱敏(手机号中间脱敏,身份证仅后4位)。

4. 指标 (Metrics)

类型 示例 注意
Counter 请求总数 / 错误总数 仅递增,不回退
Gauge 当前队列长度 / 在线用户 快速波动可取平均
Histogram 请求耗时 / 载荷大小 设定合适 bucket
Summary 自定义分位 不建议高并发全局使用

核心指标:

  • 流量:QPS / 并发连接数
  • 性能:p50/p95/p99 Latency
  • 稳定性:Error Rate / Timeout Rate
  • 资源:CPU / 内存 / GC / FD / 线程池使用率
  • 容量:队列长度 / 缓存命中率 / DB 连接池耗尽次数

5. 追踪 (Tracing)

  • 使用 OpenTelemetry:自动 + 手动埋点。
  • 根 span:入口(HTTP / 消息 / 定时任务);子 span:外部调用 / DB / MQ。
  • 上下文传递:traceparent / baggage。
  • 大包/慢调用:记录 size / costMs 标签。

5.1 Span / Trace 命名约定

场景 命名模式 示例
HTTP 入口 http.. http.GET.orders.list
RPC / 内部调用 rpc.. rpc.payment.refund
DB 查询 db.. db.postgres.select
消息生产 mq.produce. mq.produce.order.created
消息消费 mq.consume. mq.consume.order.created
定时任务 / 批处理 job. job.settlement.rollup
外部第三方 API ext.. ext.stripe.charge

规则:

  1. 动词小写;资源名复数;不含动态 ID(放 attributes:order.id=123)。
  2. 必要 attributes:http.status_code, db.statement(摘要), peer.service, retry.count
  3. 避免无语义名称(如 processTask)。名称应支持聚合统计与过滤。
  4. 入口 span 附加发布版本:service.version;错误 span 标注 error.type / error.message
  5. Attributes 不放敏感数据(账号、密钥、PII)。

6. 事件 (Events)

  • 业务事件(下单成功 / 支付失败)结构化发往事件总线供分析。
  • 标准字段:eventId / eventType / occurredAt / version / payload。

7. 告警 (Alerting)

原则:只报警“需要人干预”的情况。

类别 例子 动作
可用性 Error Rate > 阈值 立刻通知值班 & 降级
性能 p99 > SLA * 1.5 持续 5 分钟 调整扩容/排查热点
资源 CPU > 85% 持续 10 分钟 扩容 / 优化任务
安全 失败登录暴增 启动风控策略
数据 队列堆积超阈 清理/扩容/暂停上游

Read the full file on GitHub · 135 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 135 lines · 13 tokens per session scan A ccb93c0831fc

Subscribe to this mod's changes

observability is a cursor rule published in the GitHub repository mywand/cusrsor-do-it (2 stars, last pushed 7mo ago), licensed Apache-2.0. It adds 13 tokens to every session and 1,732 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.