本文へ移動
cccskills
無料GitHub で公開

logging-error-tracking-expert

Expert guide for structured logging (Pino, Winston), error tracking (Sentry), log aggregation (Axiom, Datadog), request correlation, and GDPR-compliant log management / Panduan ahli untuk logging terstruktur (Pino, Winston), pelacakan error (Sentry), agregasi log, korelasi request, dan manajemen log sesuai GDPR.

日本語の概要は準備中です。原文の説明を表示しています。

roedyrustam/vibes-plugスター 114(GitHub 114 + cccskills 0)
連携ツールSlackSentryDatadog

実行スコア 未検証

インストール方法を見る

含まれるファイル(1)

  • SKILL.md13.1 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Logging & Error Tracking Expert (2026 Edition)

English | Bahasa Indonesia


<a name="english"></a>

English

Orchestration & Integration

  • Upstream Orchestrators: Works under brainstorming and zero-to-prod-orchestrator (Phase 7 - Monitoring & Production Telemetry) to provide unified logging and alert handling.
  • Downstream Cooperating Skills:
    • data-telemetry-expert — OpenTelemetry spans + log correlation.
    • error-resilience-expert — Error tracking, circuit breakers, and monitoring setup.
    • js-backend-expert — Server-side logging middleware (Fastify/Hono/Express).
    • ci-cd-devops-architect — Source map upload in CI/CD pipelines.
    • production-ready-hardener — Pre-launch logging and monitoring audit checklist.
    • zero-trust-secret-vault — Secure redaction and logging of secret access patterns.
    • session-memory-manager — Store error logs and operational telemetry states.

Description

Production-grade guide for implementing structured logging, error tracking, and application monitoring. Covers Pino (high-performance JSON logging), Sentry SDK integration (React, Node.js, Next.js), source map upload for production errors, request ID correlation across microservices, log aggregation (Axiom, Datadog, Logflare), alert rules, GDPR-compliant log redaction (PII masking), and OpenTelemetry integration.

Trigger Conditions

Activate this skill when:

  • Setting up structured logging for Node.js/Bun backend services.
  • Integrating Sentry for error tracking in React/Next.js apps.
  • Implementing request ID correlation across microservices.
  • Setting up log aggregation and search (Axiom, Datadog, Grafana Loki).
  • Configuring alerting rules for production errors.
  • Implementing GDPR-compliant log management (PII redaction).
  • Setting up source map uploads for production debugging.

Logging Library Selection Guide

LibraryBest ForPerformanceOutput Format
PinoHigh-throughput Node.js services⭐⭐⭐⭐⭐ (fastest)JSON (structured)
WinstonEnterprise, multiple transports⭐⭐⭐Configurable
BunyanLegacy projects⭐⭐⭐⭐JSON
console.logNever in production❌Unstructured

Recommendation: Use Pino for all production services (10x faster than Winston, native JSON).


1. Structured Logging with Pino

// lib/logger.ts
import pino from 'pino';

export const logger = pino({
  level: process.env.LOG_LEVEL ?? 'info',
  // Redact sensitive fields (GDPR/PII)
  redact: {
    paths: ['req.headers.authorization', 'req.headers.cookie', '*.password', '*.token', '*.ssn', '*.creditCard'],
    censor: '[REDACTED]',
  },
  // Standardized format
  formatters: {
    level: (label) => ({ level: label }),
    bindings: (bindings) => ({
      service: process.env.SERVICE_NAME ?? 'app',
      environment: process.env.NODE_ENV,
      version: process.env.APP_VERSION,
      pid: bindings.pid,
      hostname: bindings.hostname,
    }),
  },
  timestamp: pino.stdTimeFunctions.isoTime,
});

// Child logger for specific domain
export const dbLogger = logger.child({ module: 'database' });
export const authLogger = logger.child({ module: 'auth' });
export const paymentLogger = logger.child({ module: 'payment' });

Log Level Strategy

// When to use each level:
logger.fatal('Application cannot start — exiting');       // Process crash
logger.error({ err }, 'Payment processing failed');        // Failed operations (needs attention)
logger.warn('Rate limit threshold at 80%');                // Degraded state, approaching limits
logger.info({ userId, action: 'login' }, 'User logged in'); // Business events, audit trail
logger.debug({ query, params }, 'Database query executed'); // Development troubleshooting
logger.trace({ request }, 'Incoming request');              // Extreme detail (rarely enabled)

2. Request ID Correlation

// middleware/request-id.ts
import { randomUUID } from 'crypto';
import { AsyncLocalStorage } from 'async_hooks';

// Async context for request correlation
export const requestContext = new AsyncLocalStorage<{ requestId: string }>();

export function requestIdMiddleware(req: Request): string {
  // Use incoming header or generate new ID
  const requestId = req.headers.get('x-request-id') ?? randomUUID();

  // Propagate to downstream services
  return requestId;
}

// Usage with Pino child logger
export function getRequestLogger() {
  const ctx = requestContext.getStore();
  return ctx ? logger.child({ requestId: ctx.requestId }) : logger;
}

// In API route
export async function GET(request: Request) {
  const requestId = requestIdMiddleware(request);

  return requestContext.run({ requestId }, async () => {
    const log = getRequestLogger();
    log.info('Processing request');

    // All downstream log calls include requestId automatically
    const result = await fetchData(log);
    return Response.json(result);
  });
}

3. Sentry Integration (Next.js)

// sentry.client.config.ts
import * as Sentry from '@sentry/nextjs';

Sentry.init({
  dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
  environment: process.env.NODE_ENV,
  release: process.env.SENTRY_RELEASE,

  // Performance monitoring
  tracesSampleRate: process.env.NODE_ENV === 'production' ? 0.1 : 1.0,

  // Session replay for debugging
  replaysSessionSampleRate: 0.01, // 1% of sessions
  replaysOnErrorSampleRate: 1.0,   // 100% of error sessions

  integrations: [
    Sentry.replayIntegration({ maskAllText: false, blockAllMedia: false }),
  ],

  // Filter noise
  ignoreErrors: [
    'ResizeObserver loop',
    'Non-Error promise rejection',
    /Loading chunk \d+ failed/,
  ],

  // Scrub PII before sending
  beforeSend(event) {
    if (event.user) {
      delete event.user.ip_address;
      delete event.user.email; // Or hash it
    }
    return event;
  },
});
// sentry.server.config.ts
import * as Sentry from '@sentry/nextjs';

Sentry.init({
  dsn: process.env.SENTRY_DSN,
  tracesSampleRate: 0.1,

  // Capture unhandled promise rejections
  integrations: [
    Sentry.prismaIntegration(), // Auto-track Prisma queries
  ],
});

Source Map Upload (CI/CD)

# .github/workflows/deploy.yml
- name: Upload Source Maps to Sentry
  env:
    SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
    SENTRY_ORG: your-org
    SENTRY_PROJECT: your-project
  run: |
    npx @sentry/cli sourcemaps upload \
      --release=${{ github.sha }} \
      .next/static

4. Log Aggregation Setup (Axiom)

// lib/axiom-transport.ts
import { pino } from 'pino';

// Pino transport for Axiom (or any HTTP log service)
const transport = pino.transport({
  targets: [
    // Console output (development)
    { target: 'pino-pretty', level: 'debug' },
    // Axiom (production)
    {
      target: '@axiomhq/pino',
      level: 'info',
      options: {
        dataset: process.env.AXIOM_DATASET,
        token: process.env.AXIOM_TOKEN,
      },
    },
  ],
});

export const logger = pino(transport);

5. Alert Rules Configuration

// Example alert conditions to configure in your monitoring tool
const ALERT_RULES = {
  criticalErrors: {
    condition: 'error count > 50 in 5 minutes',
    severity: 'critical',
    notification: ['pagerduty', 'slack'],
  },
  highErrorRate: {
    condition: 'error rate > 5% of total requests',
    severity: 'high',
    notification: ['slack'],
  },
  slowResponses: {
    condition: 'p99 response time > 3000ms for 10 minutes',
    severity: 'medium',
    notification: ['slack'],
  },
  diskSpace: {
    condition: 'disk usage > 85%',
    severity: 'warning',
    notification: ['email'],
  },
};

6. GDPR-Compliant Log Management

// lib/pii-redactor.ts

/** Fields that must be redacted in logs */
const PII_PATTERNS = [
  /\b\d{3}-\d{2}-\d{4}\b/g,           // SSN
  /\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/g, // Credit card
  /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g, // Email
];

export function redactPII(text: string): string {
  let result = text;
  for (const pattern of PII_PATTERNS) {
    result = result.replace(pattern, '[REDACTED]');
  }
  return result;
}

// Log retention policy
const LOG_RETENTION = {
  debug: '7 days',
  info: '30 days',
  warn: '90 days',
  error: '365 days',
  audit: '7 years', // Compliance requirement
};

Common Pitfalls to Avoid

Anti-PatternProblemCorrect Approach
console.log in productionUnstructured, no levels, no rotationUse Pino with JSON output
Logging PII (emails, passwords)GDPR violation, security riskUse Pino redact option
No request correlation IDCan't trace requests across servicesPropagate x-request-id header
Logging everything at info levelLog noise, storage wasteUse appropriate levels (debug/info/warn/error)
No source maps in production errors"Minified React error #xxx"Upload source maps to Sentry
No log rotation/retention policyDisk fills up, storage costs growSet TTL per level, archive old logs
Alerting on every errorAlert fatigueSet meaningful thresholds and severity levels

<a name="bahasa-indonesia"></a>

Bahasa Indonesia

Integrasi Orkestrasi

  • Orkestrator Hulu: Beroperasi di bawah arahan brainstorming dan zero-to-prod-orchestrator (Fase 7 - Pemantauan & Telemetri Produksi) untuk menyediakan logging terpadu dan penanganan alert.
  • Skill Hilir & Kerja Sama:
    • data-telemetry-expert — Span OpenTelemetry + korelasi log.
    • error-resilience-expert — Setup pelacakan error, circuit breaker, dan monitoring.
    • js-backend-expert — Middleware logging sisi server (Fastify/Hono/Express).
    • ci-cd-devops-architect — Upload source map dalam pipeline CI/CD.
    • production-ready-hardener — Audit logging dan monitoring pra-peluncuran.
    • zero-trust-secret-vault — Redaksi aman dan logging pola akses rahasia.
    • session-memory-manager — Menyimpan log error dan status telemetri operasional.

Deskripsi

Panduan tingkat produksi untuk mengimplementasikan logging terstruktur, pelacakan error, dan pemantauan aplikasi. Mencakup Pino (logging JSON berkinerja tinggi), integrasi SDK Sentry (React, Node.js, Next.js), upload source map untuk error produksi, korelasi request ID lintas microservice, agregasi log (Axiom, Datadog, Logflare), aturan alerting, redaksi log sesuai GDPR / UU PDP (masking PII), dan integrasi OpenTelemetry.

Kondisi Pemicu

Aktifkan skill ini ketika:

  • Menyiapkan logging terstruktur untuk layanan backend Node.js/Bun.
  • Mengintegrasikan Sentry untuk pelacakan error di aplikasi React/Next.js.
  • Mengimplementasikan korelasi request ID lintas microservice.
  • Menyiapkan agregasi dan pencarian log (Axiom, Datadog, Grafana Loki).
  • Mengonfigurasi aturan alerting untuk error produksi.
  • Mengimplementasikan manajemen log sesuai GDPR dan UU PDP (redaksi PII).

Implementasi Pola Kunci (TypeScript)

1. Logger Terstruktur Berkinerja Tinggi dengan Pino & Redaksi PII

// lib/logger.ts
import pino from 'pino';

export const logger = pino({
  level: process.env.LOG_LEVEL ?? 'info',
  // Redaksi field sensitif otomatis (Kepatuhan UU PDP & GDPR)
  redact: {
    paths: [
      'req.headers.authorization',
      'req.headers.cookie',
      '*.password',
      '*.token',
      '*.nik',
      '*.nomorKartu',
    ],
    censor: '[TEREDAKSI]',
  },
  formatters: {
    level: (label) => ({ level: label }),
    bindings: (bindings) => ({
      layanan: process.env.SERVICE_NAME ?? 'backend-api',
      lingkungan: process.env.NODE_ENV,
      pid: bindings.pid,
      hostname: bindings.hostname,
    }),
  },
  timestamp: pino.stdTimeFunctions.isoTime,
});

export const dbLogger = logger.child({ modul: 'database' });
export const paymentLogger = logger.child({ modul: 'pembayaran' });

2. Korelasi Request ID dengan AsyncLocalStorage

import { randomUUID } from 'crypto';
import { AsyncLocalStorage } from 'async_hooks';
import { logger } from './logger';

export const konteksRequest = new AsyncLocalStorage<{ requestId: string }>();

export function getLoggerRequest() {
  const ctx = konteksRequest.getStore();
  return ctx ? logger.child({ requestId: ctx.requestId }) : logger;
}

3. Inisialisasi Sentry Klien di Next.js 15

// sentry.client.config.ts
import * as Sentry from '@sentry/nextjs';

Sentry.init({
  dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
  environment: process.env.NODE_ENV,
  tracesSampleRate: process.env.NODE_ENV === 'production' ? 0.1 : 1.0,
  replaysOnErrorSampleRate: 1.0, // Rekam 100% sesi yang mengalami error
});

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

コメント

ログインなしで書き込めます。使ってみた感想、質問、動かなかった環境などを気軽にどうぞ。

まだコメントはありません。最初のコメントを書いてみませんか。

送信するとすぐに公開されます。メールアドレスや電話番号などの個人情報は書かないでください。URL は 2 つまでです。

0 / 1000 文字

このフォームは reCAPTCHA で保護されており、Google のプライバシーポリシーと利用規約が適用されます。

同じリポジトリのスキル

A2A agent protocol interoperability, Agent Cards, and MCP bridging / Protokol agen A2A, Agent Cards, dan integrasi MCP.

日本語の概要は準備中です。原文の説明を表示しています。

roedyrustam/vibes-plug1142026年10月27日 更新

Expert guide for automated and manual Web Accessibility (a11y) testing — axe-core, Pa11y, Playwright a11y, screen reader testing, and WCAG 2.2 Level AA/AAA compliance / Panduan ahli pengujian aksesibilitas web.

日本語の概要は準備中です。原文の説明を表示しています。

roedyrustam/vibes-plug1142026年10月27日 更新

Web accessibility testing with axe-core, Playwright, and WCAG 2.2 / Pengujian aksesibilitas web axe-core, Playwright, dan WCAG 2.2.

日本語の概要は準備中です。原文の説明を表示しています。

roedyrustam/vibes-plug1142026年10月27日 更新

Expert guide for intelligent model cascading and routing — complexity-scored task routing from Flash/Haiku to Sonnet/Opus/Astra, dynamic escalation with quality gates, 40-60% token cost reduction while maintaining output quality / Panduan ahli untuk kaskade dan routing model cerdas — routing tugas berbasis skor kompleksitas dari Flash/Haiku ke Sonnet/Opus/Astra, eskalasi dinamis dengan gerbang kualitas, pengurangan biaya token 40-60% dengan kualitas output terjaga.

日本語の概要は準備中です。原文の説明を表示しています。

roedyrustam/vibes-plug1142026年10月27日 更新

Model cascading & complexity-scored routing (Grok, Gemini, Claude) / Routing kaskade model & scoring kompleksitas (Grok, Gemini, Claude).

日本語の概要は準備中です。原文の説明を表示しています。

roedyrustam/vibes-plug1142026年10月27日 更新

Affective computing, emotion AI, and multimodal sentiment analysis / Komputasi afektif, AI emosional, dan analisis sentimen multimodal.

日本語の概要は準備中です。原文の説明を表示しています。

roedyrustam/vibes-plug1142026年10月27日 更新

roedyrustam のスキルをすべて見る

このスキルの問題を報告する