Skip to content

A portfolio project demonstrating distributed tracing and observability using OpenTelemetry, microservices, Docker, and Terraform on AWS.

Notifications You must be signed in to change notification settings

jeziellopes/observability

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Observability Demo - Microservices with OpenTelemetry

A portfolio project demonstrating distributed tracing and observability using OpenTelemetry, microservices, Docker, and Terraform on AWS.

🎯 Project Overview

This project showcases:

  • Microservices Architecture - 4 TypeScript services with REST APIs
  • Distributed Tracing - OpenTelemetry instrumentation across all services
  • Async Processing - Redis queue with trace context propagation
  • Serverless Integration - AWS Lambda with tracing
  • Container Orchestration - Docker Compose for local dev, ECS Fargate for production
  • Infrastructure as Code - Terraform for AWS deployment

πŸ“Š Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Client    β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       v
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  API Gateway    │──────────────┐
β”‚   (Port 3000)   β”‚              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β”‚
         β”‚                       β”‚
    β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”                  β”‚
    β”‚         β”‚                  β”‚
    v         v                  v
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  User   β”‚ β”‚  Order  β”‚    β”‚ Lambda  β”‚
β”‚ Service β”‚ β”‚ Service β”‚    β”‚Validatorβ”‚
β”‚  :3001  β”‚ β”‚  :3002  β”‚    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
                 β”‚
                 v
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚  Redis  β”‚
            β”‚  Queue  β”‚
            β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
                 β”‚
                 v
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚Notification β”‚
          β”‚   Service   β”‚
          β”‚    :3003    β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
                 v
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚   Jaeger    β”‚
          β”‚ (Tracing UI)β”‚
          β”‚   :16686    β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  • Node.js 20+
  • Docker & Docker Compose
  • AWS CLI (for deployment)
  • Terraform (for infrastructure)

Local Development

  1. Clone and setup
git clone <repository>
cd observability
  1. Start all services
docker-compose up --build
  1. Access services

Test Distributed Tracing

# Create a user
curl -X POST http://localhost:3000/api/users \
  -H "Content-Type: application/json" \
  -d '{"name": "John Doe", "email": "john@example.com"}'

# Create an order (triggers full trace across services)
curl -X POST http://localhost:3000/api/orders \
  -H "Content-Type: application/json" \
  -d '{
    "userId": 1,
    "items": ["Product A", "Product B"],
    "total": 149.99
  }'

# View trace in Jaeger
open http://localhost:16686

πŸ“ Project Structure

observability/
β”œβ”€β”€ services/
β”‚   β”œβ”€β”€ api-gateway/         # Entry point service
β”‚   β”œβ”€β”€ user-service/        # User management
β”‚   β”œβ”€β”€ order-service/       # Order processing + queue
β”‚   └── notification-service/ # Queue consumer
β”œβ”€β”€ lambda/                  # Serverless function
β”‚   └── src/index.ts        # Order validator
β”œβ”€β”€ infrastructure/
β”‚   └── terraform/          # AWS deployment
β”œβ”€β”€ configs/                # Shared OpenTelemetry config
β”œβ”€β”€ docker-compose.yml      # Local orchestration
β”œβ”€β”€ PLAN.md                 # Implementation plan
└── TASKS.md               # Detailed task list

πŸ” Observability Features

OpenTelemetry Instrumentation

  • Automatic: HTTP requests, database calls, Redis operations
  • Manual: Custom business logic spans
  • Context Propagation: Traces flow across service boundaries and queues

Trace Scenarios

  1. API Gateway β†’ User Service - Simple request flow
  2. API Gateway β†’ Order Service β†’ User Service - Multi-service call
  3. Order Service β†’ Redis β†’ Notification Service - Async processing
  4. API Gateway β†’ Lambda - Serverless integration

Jaeger Features

  • View end-to-end request traces
  • Analyze service dependencies
  • Identify performance bottlenecks
  • Track error propagation

πŸ› οΈ Development

Build individual service

cd services/api-gateway
npm install
npm run build
npm start

Run in development mode

npm run dev  # Uses ts-node

Build Lambda function

cd lambda
npm install
npm run build  # Creates lambda.zip

☁️ AWS Deployment

1. Build and push Docker images

export AWS_ACCOUNT_ID="your-account-id"
export AWS_REGION="us-east-1"

# Login to ECR
aws ecr get-login-password --region $AWS_REGION | \
  docker login --username AWS --password-stdin \
  $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com

# Build and push
./infrastructure/scripts/build-and-push.sh

2. Deploy with Terraform

cd infrastructure/terraform
cp terraform.tfvars.example terraform.tfvars
# Edit terraform.tfvars

terraform init
terraform plan
terraform apply

3. Get endpoints

terraform output api_gateway_url
terraform output lambda_function_name

πŸ“Š Monitoring

CloudWatch Logs

aws logs tail /ecs/observability-demo --follow

Service Health

curl http://<alb-dns>/health

Lambda Invocation

aws lambda invoke \
  --function-name observability-demo-order-validator \
  --payload '{"body":"{\"userId\":1,\"items\":[\"test\"],\"total\":99.99}"}' \
  response.json

πŸ§ͺ Testing

API Endpoints

Users

# Get all users
GET /api/users

# Get user by ID
GET /api/users/:id

# Create user
POST /api/users
{
  "name": "Jane Doe",
  "email": "jane@example.com"
}

Orders

# Get all orders
GET /api/orders

# Get order by ID (includes user data)
GET /api/orders/:id

# Create order (validates user, publishes to queue)
POST /api/orders
{
  "userId": 1,
  "items": ["Item 1", "Item 2"],
  "total": 99.99
}

πŸŽ“ Learning Outcomes

This project demonstrates:

  • TypeScript in production microservices
  • OpenTelemetry SDK integration
  • Distributed tracing patterns
  • Service-to-service communication
  • Async messaging with trace context
  • Container orchestration
  • Infrastructure as Code
  • Serverless observability

πŸ“ Documentation

πŸ’° Cost Estimation (AWS)

  • ECS Fargate: ~$30-50/month (minimal CPU/memory)
  • ALB: ~$16/month
  • NAT Gateway: ~$32/month
  • Lambda: Free tier eligible
  • CloudWatch: Free tier eligible

Total: ~$80-100/month (can be reduced using spot instances)

🧹 Cleanup

Local

docker-compose down -v

AWS

cd infrastructure/terraform
terraform destroy

πŸ” Security Notes

⚠️ This is a demo project - not production-ready:

  • No authentication/authorization
  • Public ALB with HTTP only
  • No secret management
  • Basic security groups
  • No WAF or DDoS protection

For production:

  • Add AWS WAF
  • Use HTTPS with ACM certificates
  • Implement AWS Secrets Manager
  • Add API authentication (JWT, API keys)
  • Enable VPC Flow Logs
  • Implement proper IAM policies

🀝 Contributing

This is a portfolio project, but feedback is welcome!

πŸ“„ License

MIT

πŸ™‹ Contact

Portfolio project by [Your Name]

  • GitHub: [your-github]
  • LinkedIn: [your-linkedin]

Built with: TypeScript β€’ Node.js β€’ Express β€’ OpenTelemetry β€’ Jaeger β€’ Redis β€’ Docker β€’ AWS ECS β€’ Lambda β€’ Terraform

About

A portfolio project demonstrating distributed tracing and observability using OpenTelemetry, microservices, Docker, and Terraform on AWS.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published