A comprehensive demonstration of distributed tracing and observability in microservices architecture using .NET 8, OpenTelemetry, and modern observability tools.
TwinTrace showcases a complete observability stack for monitoring distributed applications. It consists of two microservices that communicate with each other, with full instrumentation for traces, metrics, and logs using OpenTelemetry standards.
- ApiOne - Data Collection Service (Port 7160)
- ApiTwo - Analytics Engine Service (Port 7161)
- OpenTelemetry Collector - Centralized telemetry collection
- Prometheus - Metrics storage and querying
- Grafana - Metrics visualization and dashboards
- Jaeger - Distributed tracing visualization
- Distributed Tracing: End-to-end request tracing across microservices
- Metrics Collection: Application and infrastructure metrics
- Centralized Logging: Structured logging with correlation IDs
- Observability Stack: Complete monitoring solution with Prometheus, Grafana, and Jaeger
- Docker Compose: Easy deployment and development setup
- OpenTelemetry Integration: Standards-based instrumentation
git clone https://github.com/yourusername/TwinTrace.git
cd TwinTracedocker-compose up -dThis will start:
- OpenTelemetry Collector (Ports: 4317, 4318, 4319)
- Prometheus (Port: 9090)
- Grafana (Port: 3000) - Username:
admin, Password:admin - Jaeger (Port: 16686)
# Build and run both APIs
docker-compose -f docker-compose.yaml up --build# Terminal 1 - Run ApiOne
cd ApiOne
dotnet run
# Terminal 2 - Run ApiTwo
cd ApiTwo
dotnet runcurl -X POST "https://localhost:7160/api/Event/SendEvent" \
-H "Content-Type: application/json" \
-d '{
"userId": "12345",
"eventSource": "WebApp",
"eventType": "PageView",
"eventData": "HomePage",
"eventTime": "2024-01-15T10:30:00Z"
}'- Grafana: http://localhost:3000 (admin/admin)
- Jaeger: http://localhost:16686
- Prometheus: http://localhost:9090
- ApiOne Swagger: https://localhost:7160/swagger
- ApiTwo Swagger: https://localhost:7161/swagger
- Request duration and throughput
- Error rates and status codes
- HTTP client metrics
- Custom business metrics
TwinTrace/
βββ ApiOne/ # Data Collection Service
β βββ Controllers/ # API endpoints
β βββ Models/ # Data models
β βββ Services/ # Business logic
β βββ Interfaces/ # Service contracts
β βββ Program.cs # Application entry point
βββ ApiTwo/ # Analytics Engine Service
β βββ Controllers/ # API endpoints
β βββ Models/ # Data models
β βββ Services/ # Business logic
β βββ Interfaces/ # Service contracts
β βββ Program.cs # Application entry point
βββ docker-compose.yaml # Container orchestration
βββ otel-collector-config.yaml # OpenTelemetry configuration
βββ prometheus.yml # Prometheus configuration
βββ TwinTrace.sln # Visual Studio solution
The collector is configured to:
- Receive OTLP traces, metrics, and logs
- Export traces to Jaeger
- Export metrics to Prometheus
- Provide debug output for development
Configured to scrape metrics from the OpenTelemetry Collector every 15 seconds.
Both APIs are configured with:
- OpenTelemetry instrumentation for ASP.NET Core
- HTTP client instrumentation
- Console and OTLP exporters
- Structured logging
- Send Events: Use the
/api/Event/SendEventendpoint in ApiOne - View Traces: Check Jaeger UI for distributed traces
- Monitor Metrics: View Prometheus metrics and Grafana dashboards
- Check Logs: Monitor application logs in the console
POST /api/Event/SendEvent- Send user events to ApiTwo
POST /api/Collector/ReceiveEvents- Receive and process events
- Port Conflicts: Ensure ports 7160, 7161, 9090, 3000, 16686 are available
- Docker Issues: Make sure Docker Desktop is running
- SSL Certificates: For HTTPS, you may need to trust development certificates
dotnet dev-certs https --trust- Trace Correlation: All requests are correlated using trace IDs
- Structured Logging: Logs include structured data for better analysis
- Metrics Aggregation: Metrics are collected at regular intervals
- Error Handling: Comprehensive error tracking and logging
- 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
This project is licensed under the MIT License - see the LICENSE file for details.
- OpenTelemetry for the observability framework
- Prometheus for metrics collection
- Grafana for visualization
- Jaeger for distributed tracing
For questions and support:
- Open an issue on GitHub
- Check the documentation
- Review the configuration files
Happy Observing! πβ¨