This project demonstrates a complete microservices architecture with distributed tracing using OpenTelemetry and Jaeger.
The application consists of 3 microservices:
- User Service (Port 3001) - Manages user data and initiates orders
- Order Service (Port 3002) - Handles order creation and management
- Notification Service (Port 3003) - Sends notifications for order events
- Distributed Tracing: Full request tracing across all microservices
- OpenTelemetry Integration: Automatic and manual instrumentation
- Jaeger UI: Visual trace inspection and analysis
- Service Communication: HTTP-based inter-service communication
- Error Tracking: Exception handling and error propagation in traces
- Custom Spans: Manual span creation for business logic
- Span Attributes: Rich metadata for better observability
-
Clone and navigate to the project directory:
git clone <your-repo-url> cd microservices-tracing-demo
-
Start all services:
docker-compose up --build
-
Wait for all services to be ready (about 30-60 seconds)
-
Access the Jaeger UI: Open http://localhost:16686 in your browser
# Check if all services are running
curl http://localhost:3001/health # User Service
curl http://localhost:3002/health # Order Service
curl http://localhost:3003/health # Notification ServiceExecute this command to create a full distributed trace:
curl -X POST http://localhost:3001/users/1/orders \
-H "Content-Type: application/json" \
-d '{
"items": [
{"name": "iPhone 15", "price": 999.99, "quantity": 1},
{"name": "AirPods Pro", "price": 249.99, "quantity": 1}
],
"totalAmount": 1249.98
}'This single request will:
- Hit the User Service
- Validate the user exists
- Call the Order Service to create an order
- Call the Notification Service to send notifications
- Generate a complete distributed trace
# Get all users
curl http://localhost:3001/users
# Get specific user
curl http://localhost:3001/users/1
# Get all orders
curl http://localhost:3002/orders
# Get all notifications
curl http://localhost:3003/notifications
# Get notifications for a specific user
curl http://localhost:3003/notifications/user/1- Open Jaeger UI: http://localhost:16686
- Select Service: Choose from
user-service,order-service, ornotification-service - Click "Find Traces" to see all traces
- Click on a trace to see the detailed span timeline
- Explore spans to see:
- Service boundaries
- Request flow
- Timing information
- Custom attributes and events
- Error details (if any)
- Service Map: Visual representation of service dependencies
- Span Details: Click on individual spans to see attributes, events, and logs
- Error Traces: Intentionally cause errors to see how they appear in traces
- Performance Analysis: Compare timing across different requests
- Custom Attributes: See business-specific metadata in spans
- Manages user information
- Initiates order creation process
- Validates user existence before order creation
- Creates and manages orders
- Calculates order totals
- Triggers notification sending
- Sends email and push notifications
- Supports multiple notification types
- Tracks notification delivery status
All services support these environment variables:
PORT: Service port (default: 3001/3002/3003)JAEGER_ENDPOINT: Jaeger collector URL- Service-specific URLs for inter-service communication
docker-compose down# Scale order service to 3 instances
docker-compose up --scale order-service=3# View logs for a specific service
docker-compose logs -f user-service# Rebuild and restart
docker-compose down
docker-compose up --build- Services not starting: Check if ports 3001, 3002, 3003, and 16686 are available
- Traces not appearing: Wait 10-15 seconds after making requests
- Connection errors: Ensure all services are fully started before testing
- Build errors: Make sure Docker and Docker Compose are properly installed
This project demonstrates:
- Microservices architecture patterns
- Distributed tracing implementation
- OpenTelemetry instrumentation
- Service-to-service communication
- Error handling in distributed systems
- Observability best practices
- Add database integration
- Implement authentication and authorization
- Add metrics collection with Prometheus
- Implement circuit breakers
- Add API gateway
- Implement event-driven architecture with message queues