Agent Skillslukevella/rallly › logging

logging

GitHub

定义项目日志规范,采用宽事件模式,要求每个请求生成包含完整上下文(元数据、业务、错误等)的单条结构化日志。提供中间件实现模式及反模式示例,指导如何优化可观测性与查询效率。

.agents/skills/logging/SKILL.md lukevella/rallly

Trigger Scenarios

编写代码时添加日志记录 需要实现请求追踪或增强系统可观测性

Install

npx skills add lukevella/rallly --skill logging -g -y
More Options

Non-standard path

npx skills add https://github.com/lukevella/rallly/tree/main/.agents/skills/logging -g -y

Use without installing

npx skills use lukevella/rallly@logging

指定 Agent (Claude Code)

npx skills add lukevella/rallly --skill logging -a claude-code -g -y

安装 repo 全部 skill

npx skills add lukevella/rallly --all -g -y

预览 repo 内 skill

npx skills add lukevella/rallly --list

SKILL.md

Frontmatter
{
    "name": "logging",
    "description": "Wide events logging pattern and conventions for this project. Use when writing logging code, adding observability, or implementing request tracing.",
    "user-invocable": false
}

Logging Guidelines

This project follows the Wide Events pattern. Logs are optimized for querying, not writing.

Core Principle

Emit one comprehensive event per request per service containing all contextual information. Do not scatter log statements throughout your code.

Wrong mental model: Log what your code is doing Correct mental model: Log what happened to this request

Wide Event Structure

Each event should include:

{
  // Request metadata
  requestId: string,
  traceId: string,
  timestamp: Date,
  service: string,

  // HTTP details
  method: string,
  path: string,
  statusCode: number,
  durationMs: number,

  // User context
  userId?: string,
  subscriptionTier?: string,

  // Business context
  pollId?: string,
  spaceId?: string,
  featureFlags: Record<string, boolean>,

  // Error details (when applicable)
  errorType?: string,
  errorCode?: string,
  errorMessage?: string,
  isRetriable?: boolean,

  // Performance metrics
  dbQueryCount?: number,
  dbQueryDurationMs?: number
}

Implementation Pattern

Use middleware to build the event throughout the request lifecycle:

  1. Initialize event at request start with request/service metadata
  2. Enrich with user context after authentication
  3. Add business context as processing occurs
  4. Emit single event in finally block after request completes

Anti-Patterns

Never do these:

  • Scattered console.log statements throughout code
  • String-based log messages without structured data
  • Low-context logs with only timestamp, level, and message
  • Multiple log lines for a single request

Example of what NOT to do:

// BAD - scattered, low-context logs
console.log("Starting request");
console.log("User authenticated");
console.log("Fetching poll");
console.log("Request complete");

Example of correct approach:

// GOOD - single wide event with full context
logger.info({
  requestId: ctx.requestId,
  userId: ctx.user?.id,
  pollId: params.pollId,
  method: "GET",
  path: "/api/polls/:id",
  statusCode: 200,
  durationMs: 45,
  dbQueryCount: 2,
  dbQueryDurationMs: 12
});

Tail Sampling

When implementing log sampling, make decisions after request completion:

Always capture 100%:

  • All errors (5xx status, exceptions)
  • Requests exceeding p99 latency
  • Pro/enterprise user requests
  • Requests with feature flags under rollout

Sample remaining traffic: 1-5% of successful, fast requests

High-Cardinality Data

Include high-cardinality fields (userId, pollId, requestId). Modern observability tools handle this efficiently. Aim for 50+ fields per event. Include:

  • All IDs involved in the request
  • All feature flags evaluated
  • All external service calls made
  • Timing breakdown for significant operations
  • User tier and account metadata

Version History

  • afeccb9 Current 2026-08-20 16:47

Same Skill Collection

.agents/skills/better-auth-best-practices/SKILL.md
.agents/skills/create-auth-skill/SKILL.md
.agents/skills/devmoji/SKILL.md
.agents/skills/email-and-password-best-practices/SKILL.md
.agents/skills/organization-best-practices/SKILL.md
.agents/skills/prisma-cli/SKILL.md
.agents/skills/prisma-client-api/SKILL.md
.agents/skills/prisma-database-setup/SKILL.md
.agents/skills/prisma-postgres/SKILL.md
.agents/skills/prisma-upgrade-v7/SKILL.md
.agents/skills/two-factor-authentication-best-practices/SKILL.md
.claude/skills/fix-crowdin-pr/SKILL.md

Metadata

Files
0
Version
293d23a
Hash
70371d67
Indexed
2026-08-20 16:47

Home - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-09-24 14:05
浙ICP备14020137号-1