NestJS Project Guide

Complete instrumentation approach for NestJS APIs and microservices

Use this guide for NestJS backends where request lifecycle, dependency injection, and module boundaries must remain observable.

Architecture Scope

  • HTTP controllers and middleware chain.
  • Service/provider calls.
  • Outbound HTTP/DB/queue operations.
  1. Initialize SDK before app starts listening.
  2. Instrument request lifecycle (ingress -> handler -> response).
  3. Capture structured errors from global exception filters.
  4. Add spans around DB and external service calls.

Minimum Data Contract

  • Stable service name per app/module domain.
  • Environment and version tags in every event.
  • Correlation ID propagation through async operations.

Validation Checklist

  • 4xx/5xx errors include trace context.
  • Slow endpoints produce spans with useful attributes.
  • Startup/shutdown hooks flush telemetry correctly.

Production Hardening

  1. Bound queue and retry configuration.
  2. Add ingestion failure alerting.
  3. Validate after module refactors.
  4. Keep key rotation runbook documented.

Troubleshooting

  • No events after deploy: verify bootstrap path still initializes SDK.
  • Missing spans in async handlers: confirm context propagation.
  • High noise: reduce low-value event emission.

On this page