Modern REST API built with TypeScript, Express, and OpenTelemetry. Demonstrates observability best practices including metrics collection, structured logging, and distributed tracing.
- TypeScript - Primary development language
- Express.js - Web application framework
- OpenTelemetry - Observability instrumentation
- Prometheus - Metrics collection and storage
- Winston - Structured logging library
- Swagger/OpenAPI - API documentation
- Jest - Testing framework
- Docker - Containerization platform
- Complete REST API with CRUD operations
- Automatic Prometheus metrics collection
- Distributed tracing with OpenTelemetry
- Structured JSON logging
- Advanced health checks
- Interactive Swagger documentation
- Request validation middleware
- Rate limiting protection
- CORS configuration
- Graceful shutdown handling
- Node.js 18+
- Docker & Docker Compose
- TypeScript compiler
npm installnpm run devdocker-compose up -dmake start-full-stackGET /- Root endpointGET /health- Detailed health checkGET /metrics- Prometheus metricsGET /docs- Swagger documentation
GET /api/users- List all usersGET /api/users/:id- Get specific userPOST /api/users- Create new userPUT /api/users/:id- Update existing userDELETE /api/users/:id- Delete user
GET /api/slow- Simulate slow endpointGET /api/error- Simulate 500 errorGET /api/load/:seconds- Simulate load for X seconds
- HTTP request count and duration
- Active connection monitoring
- Memory usage tracking
- CPU utilization metrics
- Custom business metrics
- Complete HTTP request traces
- Database query tracing (simulated)
- External API call tracking
- Custom spans for business logic
- JSON-formatted log output
- Request and response logging
- Error tracking and reporting
- Performance monitoring
# Run all tests
npm test
# Run with coverage report
npm run test:coverage
# Run in watch mode
npm run test:watch# Build for production
npm run build
# Run production build
npm start
# Build Docker image
docker build -t typescript-api-observability .Available environment variables:
PORT=3000
NODE_ENV=development
LOG_LEVEL=info
ENABLE_TRACING=true
PROMETHEUS_ENABLED=true
API_RATE_LIMIT=100API endpoints:
- API Documentation: http://localhost:3000/docs
- Metrics Endpoint: http://localhost:3000/metrics
- Health Check: http://localhost:3000/health
Full stack access (when running complete setup):
- Grafana: http://localhost:3000 (admin/admin)
- Prometheus: http://localhost:9090
- Jaeger: http://localhost:16686
src/
├── controllers/ # Controladores da API
├── middleware/ # Middlewares customizados
├── models/ # Modelos de dados
├── routes/ # Definição das rotas
├── services/ # Lógica de negócio
├── telemetry/ # Configuração de observabilidade
├── types/ # Definições de tipos TypeScript
└── utils/ # Utilitários
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License - see LICENSE file for details.