Skip to content

feat(observability): structured JSON logging with trace IDs #172

Description

@chitrank2050

Problem

Current logs are human-readable but not machine-parseable. Log aggregators (Loki, CloudWatch, Datadog) need structured JSON. Trace IDs in every log line enable correlating logs with traces.

Proposed solution

  1. Replace NestJS default logger with pino or winston configured for JSON output
  2. Every log line includes: timestamp, level, message, correlationId, traceId, spanId, module, extra context
  3. Request logging middleware adds: method, path, status, duration, userId, tenantId
  4. Kafka consumer logs add: topic, partition, offset, consumerGroup
  5. Development mode: pretty-printed. Production mode: single-line JSON.

API design (if applicable)

No API change. Log format change.

Alternatives considered

  • Keep NestJS default logger — rejected. Not structured, no JSON, no trace IDs.
  • Bunyan — rejected. Pino is faster and more actively maintained.

Additional context

Add Loki to docker-compose.yml for local log aggregation. Query via Grafana.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions