Structured Logging & Centralized Log Aggregation
- What: Structured JSON logs using
pinowith per-requestcorrelationId. - Where: Applied to
novaRewards/backendservice; includes k8s Fluent Bit config and Terraform CloudWatch log groups for retention.
Configuration
LOG_LEVELenv var controls log level (defaultinfo).SERVICE_NAMEenv var sets theservicefield in logs.- Correlation ID header:
x-correlation-id(falls back tox-trace-idor generated per request).
Files added/changed
- novaRewards/backend/lib/logger.js: pino logger and pino-http middleware.
- novaRewards/backend/middleware/tracingMiddleware.js: sets
correlationIdand stores it in AsyncLocalStorage. - novaRewards/backend/server.js: mounts logging middleware and uses structured logging in error handler and startup.
- k8s/fluent-bit.yaml: Fluent Bit DaemonSet + config to forward logs to CloudWatch (placeholder variables).
- infra/logging.tf: CloudWatch log groups with retention (info=30d, error=90d).
How it works
- Each incoming request gets a
correlationIdheader assigned (or propagated if present). - The
pino-httpmiddleware emits JSON logs with fields:time,level,service,correlationId,msg. - Outbound HTTP calls from the backend include
x-correlation-idwhen available.
Next steps / deployment
- Run
terraform applyininfra/to create CloudWatch log groups (requires AWS credentials). - Deploy
k8s/fluent-bit.yamlto the cluster (update${AWS_REGION}in the ConfigMap or use a K8s secret/IRSA to grant CloudWatch permissions). - Rebuild and deploy
nova-rewards-backendimage; ensureLOG_LEVELandSERVICE_NAMEare set (defaults provided in the k8s deployment patch).