This is a minimal ASP.NET Core Web API project demonstrating how to implement OpenTelemetry for distributed tracing, metrics, and structured logging. The project includes custom middleware for logging HTTP requests and responses, and is fully containerized with Docker.
- ✅ OpenTelemetry integration with:
- Logs
- Metrics
- Traces
- ✅ Custom middleware for logging request/response bodies
- ✅ Configurable via
appsettings.json - ✅ Docker support
- ✅ Clean and extendable structure
├── Controllers/
│ └── WeatherForecastController.cs
├── Middleware/
│ └── RequestResponseLoggingMiddleware.cs
├── Configuration/
│ ├── OpenTelemetryConfig.cs
│ └── OpenTelemetryLoggingConfig.cs
├── Program.cs
├── appsettings.json
├── Dockerfile
- .NET 8 SDK
- Docker (optional)
dotnet restore
dotnet runThe API will be available at https://localhost:5001 (or http://localhost:5000).
docker build -t otel-sample .
docker run -p 5000:80 otel-sampleAll OpenTelemetry-related configuration can be found and customized in:
appsettings.jsonConfiguration/OpenTelemetryConfig.csConfiguration/OpenTelemetryLoggingConfig.cs
- Tracing, logging, and metrics are configured via OpenTelemetry SDK.
- Middleware
RequestResponseLoggingMiddlewarecaptures full HTTP traffic. - Metrics and traces are automatically collected from built-in .NET instrumentation.
- ASP.NET Core 8
- OpenTelemetry
- Serilog (optional for structured logging)
- Docker
This project is open-sourced for learning purposes. You are free to fork and modify it.
Feel free to suggest improvements or open issues. Happy tracing! 🚀