Communitygithub.com

日志与监控技能

结构化日志、Sentry 错误追踪、Axiom/Datadog 集成、日志级别与告警。

日志与监控技能 是什么?

该技能为开发者提供了一套全面的日志记录与监控最佳实践,涵盖结构化日志、错误追踪、遥测数据导出以及基于阈值的告警机制。它推荐使用 Pino 作为 Node.js 日志库,要求日志以 JSON 格式输出,并包含 `timestamp`、`level`、`message`、`requestId`、`userId` 等标准字段。日志级别严格区分 `error`(故障)、`warn`(降级)、`info`(业务事件)和 `debug`(仅开发环境)。技能同时集成了 Sentry 进行错误追踪,要求尽早初始化 SDK、捕获未处理异常并添加上下文与面包屑。可观测性数据可通过 OTLP 或原生 SDK 发送至 Axiom 或 Datadog,并支持自定义业务 KPI 指标。告警规则建议基于错误率峰值(例如 5 分钟内错误率 >5%)而非单个错误,同时监控响应时间的 p50、p95、p99 分位数,并在 p95 恶化时触发告警。该技能适用于任何使用 Node.js 和现代监控栈(如 Sentry、Axiom、Datadog)的 Web 应用或微服务架构。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/logging-monitoring

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

日志与监控

规则

  • 结构化日志:JSON 格式,包含 timestamp、level、message、requestId、userId 字段
  • 日志级别:error(故障)、warn(降级)、info(业务事件)、debug(仅开发环境)
  • 使用 Pino 进行 Node.js 日志记录 — 快速、结构化、默认 JSON 格式
  • Sentry 用于错误追踪:尽早初始化、捕获未处理异常、添加用户上下文与面包屑
  • 使用请求 ID 关联日志 — 为每个请求生成 UUID,并在所有服务调用中传递
  • 永远不要记录机密信息、密码、令牌或完整的信用卡号 — 对敏感字段进行脱敏处理
  • 基于错误率峰值而非单个错误进行告警 — 使用阈值(例如 5 分钟内错误率 >5%)
  • Axiom/Datadog:通过 OTLP 或原生 SDK 发送日志,添加自定义指标以跟踪业务 KPI
  • 健康检查端点:GET /health 返回 { status: "ok" },并包含数据库连通性检查
  • 监控响应时间的 p50、p95、p99 分位数 — 在 p95 恶化时触发告警

模式

// Pino 结构化日志
import pino from "pino";
const logger = pino({ level: process.env.LOG_LEVEL || "info" });

logger.info({ userId, action: "checkout", orderId }, "订单已下单");
logger.error({ err, requestId }, "支付处理失败");
// Sentry 初始化(Next.js)
import * as Sentry from "@sentry/nextjs";
Sentry.init({ dsn: process.env.SENTRY_DSN, tracesSampleRate: 0.1 });

避免

  • 在生产环境中使用 console.log — 改用结构化日志记录器
  • 记录每个请求的请求体 — 记录摘要,而非负载
  • 忽略未捕获的 Promise 拒绝 — 始终捕获它们
  • 因频繁告警导致告警疲劳 — 调整阈值,对相似错误进行分组

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

YepAPI/skills

WCAG 2.1 AA — semantic HTML, keyboard navigation, screen readers.

YepAPI/skills

Experiment setup, variant splitting, statistical significance, and feature flag integration.

YepAPI/skills

CRUD generators, data tables, user management, role-based access, and bulk operations.

YepAPI/skills

Monitor what ChatGPT and Gemini say about your brand using YepAPI.

YepAPI/skills

Queue workers with BullMQ/Inngest/Trigger.dev, job retries, dead letter queues, concurrency.

YepAPI/skills

Commander.js, interactive prompts with Clack, spinners, colors, config files, exit codes, and npm publishing.

YepAPI/skills

cmdk integration, Cmd+K trigger, fuzzy search, grouped actions, keyboard navigation, and dynamic action registration.

YepAPI/skills

Content planning with trend and sentiment data from YepAPI.

YepAPI/skills

Content calendar, keyword-driven planning, and content briefs.

YepAPI/skills

Theme switching with CSS variables, system preference detection, next-themes, and persistence.

YepAPI/skills

Threaded comments, @mentions, reactions, moderation queue, optimistic UI, and cursor pagination.

YepAPI/skills

Competitive analysis between domains using YepAPI.

YepAPI/skills

Layout grids, KPI cards, data tables with sorting/filtering, sidebar navigation, and responsive breakpoints.

YepAPI/skills

Data encryption — TLS everywhere, AES-256-GCM for PII, bcrypt passwords, encrypted backups.

YepAPI/skills

Chart patterns with Recharts/Nivo/D3, responsive containers, color scales, and accessibility.

YepAPI/skills

Drizzle schema definition, push vs migrate, type-safe queries, relations, transactions, and prepared statements.

YepAPI/skills

Upload handling, resize/compress, CDN delivery, blur placeholders, and next/image patterns.

YepAPI/skills

Local business and Google Maps research using YepAPI.

YepAPI/skills

Cursor-based pagination, IntersectionObserver, virtualized lists with @tanstack/react-virtual, and scroll position restoration.

YepAPI/skills

Chat UI components, streaming responses with AI SDK, context window management, and RAG patterns.

相关技能