Communitygithub.com

YepAPI 技能:日誌與監控

結構化日誌、Sentry 錯誤追蹤、Axiom/Datadog 整合、日誌層級與警示。

YepAPI 技能:日誌與監控 是什麼?

此技能提供了在 AI 代理工具(例如 Claude Code、Cursor 等)中實現穩健日誌與監控系統的完整指南。它專注於使用 Pino 進行結構化 JSON 日誌、透過 Sentry 進行錯誤追蹤,以及與 Axiom 或 Datadog 等可觀測性平台整合。技能強調了關鍵原則,例如使用請求 ID 進行關聯、對敏感資料進行清理、以及根據錯誤率閾值(例如 5 分鐘內錯誤率超過 5%)而非單一錯誤來設定警示。它也定義了標準的日誌層級(error、warn、info、debug)和健康檢查端點的模式,並包含 Node.js (Pino) 和 Next.js (Sentry) 的實作程式碼範例。透過遵循這些準則,開發者可以確保生產環境的可靠記錄、主動監控和可操作的警示,減少警報疲勞並改善除錯流程。

相容平台~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 進行錯誤追蹤:盡早初始化、捕捉未處理的例外、加入使用者上下文和 breadcrumbs
  • 使用請求 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.

相關技能