티스토리 뷰
📌 NestJS + Kubernetes & 마이크로서비스 배포: 실전 가이드 - NestJS Observability 구축 전략 – 로그, 메트릭, 트레이싱 한 번에 잡기
octo54 2025. 6. 10. 13:46📌 NestJS + Kubernetes & 마이크로서비스 배포: 실전 가이드
43. NestJS Observability 구축 전략 – 로그, 메트릭, 트레이싱 한 번에 잡기
대규모 분산 시스템에서는 문제의 조기 탐지와 추적(Observability) 이 매우 중요합니다.
NestJS 마이크로서비스 구조에서 무슨 일이 언제, 어디서, 왜 발생했는지를 추적할 수 있어야
빠른 대응과 장애 복구가 가능합니다.
이번 글에서는 NestJS 프로젝트에 로그 수집, 메트릭 측정, 트레이싱 시스템을 구축하여
실제 운영 환경에서 서비스 가시성을 확보하는 전략을 다룹니다. 🔍
✅ 1. Observability 구성 요소
요소 설명 대표 도구
Logging | 누가 무엇을 언제 했는가? | Winston, Pino |
Metrics | 얼마나 자주, 얼마나 오래 발생했는가? | Prometheus |
Tracing | 어떤 경로를 통해 호출되었는가? | OpenTelemetry, Jaeger |
✅ 2. Logging – Winston 통합
📦 설치:
npm install winston @nestjs/winston
📂 logger.ts
import { WinstonModule } from 'nestjs-winston';
import * as winston from 'winston';
export const logger = WinstonModule.createLogger({
transports: [
new winston.transports.Console({
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json()
),
}),
],
});
📂 main.ts
async function bootstrap() {
const app = await NestFactory.create(AppModule, {
logger,
});
await app.listen(3000);
}
모든 로그는 JSON 형태로 출력되어 Logstash, Datadog 등과 쉽게 연동 가능
✅ 3. Metrics – Prometheus + @willsoto/nestjs-prometheus
📦 설치:
npm install @willsoto/nestjs-prometheus prom-client
📂 app.module.ts
import { PrometheusModule } from '@willsoto/nestjs-prometheus';
@Module({
imports: [
PrometheusModule.register(),
],
})
export class AppModule {}
📂 metrics.controller.ts
@Controller('metrics')
export class MetricsController {
@Get()
@Public()
getMetrics(@InjectMetric('http_requests_total') counter: Counter<string>) {
counter.inc();
return 'metrics exposed';
}
}
📈 http://localhost:3000/metrics 로 Prometheus에서 수집 가능
✅ 4. Tracing – OpenTelemetry (OTEL)
📦 설치:
npm install @nestjs/telemetry @opentelemetry/sdk-node
📂 otel.ts
import { NodeSDK } from '@opentelemetry/sdk-node';
const sdk = new NodeSDK({
serviceName: 'nestjs-app',
});
sdk.start();
📂 main.ts
import './otel'; // OpenTelemetry 초기화
📊 Jaeger, Zipkin 등으로 Export 설정 가능
✅ 5. 통합 구성 전략
- 로그: Winston → 콘솔, 파일, Logstash로 전송
- 메트릭: Prometheus로 수집 → Grafana 시각화
- 트레이싱: OpenTelemetry로 수집 → Jaeger, Datadog 등 연동
이 3가지를 통합하면 어떤 요청이 실패했는지 → 어느 서비스에서 지연됐는지 → 어떤 경로로 호출됐는지 한눈에 파악 가능
✅ 6. Kubernetes + Observability
항목 전략
로그 수집 | FluentBit → Elasticsearch |
메트릭 수집 | Prometheus Operator |
트레이싱 | OTEL Collector + Jaeger |
Dashboard 구성 | Grafana (Logs + Metrics 통합 대시보드) |
✅ 결론: NestJS Observability = 운영의 눈
✅ NestJS는 Winston + Prometheus + OTEL로 운영 가시성 확보 가능
✅ 마이크로서비스 구조에서는 각 서비스의 로그/메트릭/트레이스를 통합해야 분석 가능
✅ Kubernetes와 결합 시 운영 효율성과 신뢰성이 극대화됨
다음 글에서는 NestJS 마이크로서비스 프로젝트를 실제 SaaS 또는 스타트업 MVP 수준으로 확장하는 운영 팁 + 구조 리팩토링 전략을 소개합니다. 🎯
🔍 다음 글 예고: NestJS MSA 운영 전략 – 구조 리팩토링 & SaaS 확장
📌 다음 편: 44. NestJS MSA 운영 리팩토링 전략
NestJS 로그 수집,NestJS 메트릭 측정,NestJS 트레이싱,NestJS Observability,NestJS Prometheus,NestJS OpenTelemetry,NestJS Winston 연동,NestJS 모니터링,Kubernetes 모니터링,NestJS 운영 가시성 구축
'project > NestJS + Kubernetes & 마이크로서비스 배포' 카테고리의 다른 글
- Total
- Today
- Yesterday
- App Router
- Docker
- REACT
- NestJS
- Python
- SEO최적화
- nodejs
- 프론트엔드
- flax
- 백엔드개발
- 웹개발
- Ktor
- fastapi
- 딥러닝
- seo 최적화 10개
- 프론트엔드면접
- CI/CD
- gatsbyjs
- Next.js
- SEO 최적화
- AI챗봇
- PostgreSQL
- Prisma
- nextJS
- llm
- kotlin
- rag
- JAX
- 개발블로그
- 파이썬알고리즘
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |