> nestjs-observability
Structured logging (Pino) and Prometheus metrics. Use when adding structured logging with Pino or Prometheus metrics to NestJS services. (triggers: main.ts, **/*.module.ts, nestjs-pino, Prometheus, Logger, reqId)
curl "https://skillshub.wtf/HoangNguyen0403/agent-skills-standard/nestjs-observability?format=md"Observability Standards
Priority: P1 (OPERATIONAL)
Logging, monitoring, and observability patterns for production applications.
- Standard: Use
nestjs-pinofor high-performance JSON logging.- Why: Node's built-in
console.logis blocking and unstructured.
- Why: Node's built-in
- Configuration:
- Redaction: Mandatory masking of sensitive fields (
password,token,email). - Context: Always inject
Loggerand set the context (LoginService).
- Redaction: Mandatory masking of sensitive fields (
Tracing (Correlation)
- Request ID: Every log line must include a
reqId(Request ID).nestjs-pinohandles this automatically usingAsyncLocalStorage.- Propagation: Pass
x-request-idto downstream microservices/database queries key to trace flows.
API Overhead & Database Benchmarking
- Execution Bucket Strategy: When performance profiling is enabled, utilize global interceptors combined with
AsyncLocalStorageto split and expose latency into logical buckets. - Headers: Expose the metrics via HTTP Headers on the response for immediate feedback during development or testing:
X-Response-Duration-Ms(Total execution time)X-DB-Execution-Ms(Time spent exclusively in database queries, tracked via TypeORM loggers)X-API-Overhead-Ms(Time spent in NestJS interceptors, guards, and serialization)
- Security: Only enable performance headers and detailed SQL benchmarking in development or when a specific feature flag (
ENABLE_PERFORMANCE_BENCHMARK) is explicitly active.
Metrics
- Exposure: Use
@willsoto/nestjs-prometheusto expose/metricsfor Prometheus scraping. - Key Metrics:
http_request_duration_seconds(Histogram)db_query_duration_seconds(Histogram)memory_usage_bytes(Gauge)
Health Checks
- Terminus: Implement explicit logic for "Liveness" (I'm alive) vs "Readiness" (I can take traffic).
- DB Check:
TypeOrmHealthIndicator/PrismaHealthIndicator. - Memory Check: Fail if Heap > 300MB (prevent crash loops).
- DB Check:
🚫 Anti-Patterns
- Do NOT use standard patterns if specific project rules exist.
- Do NOT ignore error handling or edge cases.
> related_skills --same-repo
> typescript-tooling
Development tools, linting, and build config for TypeScript. Use when configuring ESLint, Prettier, Jest, Vitest, tsconfig, or any TS build tooling. (triggers: tsconfig.json, .eslintrc.*, jest.config.*, package.json, eslint, prettier, jest, vitest, build, compile, lint)
> typescript-security
Secure coding practices for TypeScript. Use when validating input, handling auth tokens, sanitizing data, or managing secrets and sensitive configuration. (triggers: **/*.ts, **/*.tsx, validate, sanitize, xss, injection, auth, password, secret, token)
> typescript-language
Modern TypeScript standards for type safety and maintainability. Use when working with types, interfaces, generics, enums, unions, or tsconfig settings. (triggers: **/*.ts, **/*.tsx, tsconfig.json, type, interface, generic, enum, union, intersection, readonly, const, namespace)
> typescript-best-practices
Idiomatic TypeScript patterns for clean, maintainable code. Use when writing or refactoring TypeScript classes, functions, modules, or async logic. (triggers: **/*.ts, **/*.tsx, class, function, module, import, export, async, promise)