Skillshub 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)
install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/HoangNguyen0403/agent-skills-standard/nestjs-observability" ~/.claude/skills/comeonoliver-skillshub-nestjs-observability && rm -rf "$T"
manifest:
skills/HoangNguyen0403/agent-skills-standard/nestjs-observability/SKILL.mdsource content
Observability Standards
Priority: P1 (OPERATIONAL)
Logging, monitoring, and observability patterns for production applications.
- Standard: Use
for high-performance JSON logging.nestjs-pino- Why: Node's built-in
is blocking and unstructured.console.log
- Why: Node's built-in
- Configuration:
- Redaction: Mandatory masking of sensitive fields (
,password
,token
).email - Context: Always inject
and set the context (Logger
).LoginService
- Redaction: Mandatory masking of sensitive fields (
Tracing (Correlation)
- Request ID: Every log line must include a
(Request ID).reqId
handles this automatically usingnestjs-pino
.AsyncLocalStorage- Propagation: Pass
to downstream microservices/database queries key to trace flows.x-request-id
API Overhead & Database Benchmarking
- Execution Bucket Strategy: When performance profiling is enabled, utilize global interceptors combined with
to split and expose latency into logical buckets.AsyncLocalStorage - Headers: Expose the metrics via HTTP Headers on the response for immediate feedback during development or testing:
(Total execution time)X-Response-Duration-Ms
(Time spent exclusively in database queries, tracked via TypeORM loggers)X-DB-Execution-Ms
(Time spent in NestJS interceptors, guards, and serialization)X-API-Overhead-Ms
- Security: Only enable performance headers and detailed SQL benchmarking in development or when a specific feature flag (
) is explicitly active.ENABLE_PERFORMANCE_BENCHMARK
Metrics
- Exposure: Use
to expose@willsoto/nestjs-prometheus
for Prometheus scraping./metrics - Key Metrics:
(Histogram)http_request_duration_seconds
(Histogram)db_query_duration_seconds
(Gauge)memory_usage_bytes
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
- No console.log: Use nestjs-pino for async, structured, JSON-formatted logging.
- No missing reqId: Propagate
header to all downstream services and queries.x-request-id - No perf data in production by default: Gate benchmarking behind
flag.ENABLE_PERFORMANCE_BENCHMARK