| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
?? Learning Goal: Understand how to implement comprehensive observability in .NET applications using OpenTelemetry, complete with metrics, tracing, and beautiful dashboards.
This project demonstrates production-ready observability for a .NET Web API with:
OpenTelemetry is the industry standard for collecting observability data from applications:
??????????????????? ?? gRPC ???????????????????????? ?? HTTP ??????????????? ?? Queries ???????????????
? Your .NET API ? ???????????????? OpenTelemetry ? ??????????????? Prometheus ? ?????????????????? Grafana ?
? ? ? Collector ? ? (Metrics ? ? (Beautiful ?
? • Custom Spans ? ? ? ? Storage) ? ? Dashboard) ?
? • Route Metrics ? ? • Receives Telemetry ? ? ? ? ?
? • Error Tracking? ? • Processes Data ? ??????????????? ???????????????
??????????????????? ? • Exports to Backend?
????????????????????????
??? Program.cs # ?? Web API with comprehensive OpenTelemetry setup ??? AppHost/ ? ??? AppHost.cs # ??? Aspire orchestration (starts all containers) ? ??? otel-config.yml # ?? OpenTelemetry Collector configuration ? ??? prometheus.yml # ?? Prometheus scraping configuration ? ??? grafana-datasources.yml # ?? Grafana data source configuration ? ??? dashboard-provider.yml # ?? Dashboard auto-loading configuration ? ??? api-dashboard.json # ?? Pre-built production dashboard ??? docker-compose.reference.yml # ?? Production deployment reference ??? README.md # ?? This comprehensive guide
# Clone and navigate to the project
git clone <your-repo>
cd dotnet-examples
# Start the complete observability stack
cd AppHost
dotnet run?? That's it! Wait 30-60 seconds for all containers to start.
You'll see a production-ready dashboard with:
Hit different endpoints to see real-time data:
# Replace [port] with your API's actual port from Aspire dashboard
curl http://localhost:[port]/api/weather # ? Normal business logic
curl http://localhost:[port]/api/test-telemetry # ?? Custom tracing example
curl http://localhost:[port]/api/external-call # ?? HTTP client tracing
curl http://localhost:[port]/api/error # ? Error tracing
curl http://localhost:[port]/debug/telemetry # ?? Debug information?? Watch the dashboard update in real-time! Each endpoint will appear as separate lines in the charts.
?? Learning: You're seeing custom metrics that track each endpoint individually.
?? Learning: You'll see how your request flows through multiple services with timing for each step.
?? Learning: See how errors are automatically captured and visualized.
?? Learning: Understand how to identify performance bottlenecks per endpoint.
Our middleware captures detailed metrics for each endpoint:
// This runs for every HTTP request
requestCounter.Add(1, new TagList
{
{ "route", "/api/weather" }, // Which endpoint
{ "method", "GET" }, // HTTP method
{ "status_code", "200" } // Response status
});Result: Grafana can show separate lines for /api/weather, /api/error, etc.
Business logic gets detailed tracing:
using var activity = activitySource.StartActivity("GenerateWeatherForecast");
activity?.SetTag("operation.type", "weather_forecast");
activity?.SetTag("forecast.count", forecasts.Length);Result: Distributed traces show your custom business operations with timing.
The Grafana dashboard uses PromQL queries like:
# Request rate per endpoint
sum by(route) (rate(http_requests_total[1m]))
# P95 response time
histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket[1m])) by (le))
Result: Rich visualizations that update in real-time.
// 1. Define a new metric
var businessMetric = customMeter.CreateCounter<long>("business_operations_total");
// 2. Record data
businessMetric.Add(1, new TagList { { "operation", "user_signup" } });
// 3. Query in Grafana: business_operations_total// Create detailed tracing for any operation
using var activity = activitySource.StartActivity("ProcessPayment");
activity?.SetTag("payment.amount", 99.99);
activity?.SetTag("payment.method", "credit_card");
// Your payment logic here...For production, see docker-compose.reference.yml for a complete setup including:
After completing this example, you'll understand:
? How to implement OpenTelemetry in .NET applications
? Custom metrics vs automatic metrics and when to use each
? Distributed tracing for request flow analysis
? Dashboard creation for production monitoring
? Performance monitoring techniques for APIs
? Error tracking and alerting best practices
? Production deployment considerations
# Check if all containers are running
docker ps
# Restart if needed
cd AppHost && dotnet run?? Congratulations! You now have a complete, production-ready observability setup that you can adapt for any .NET application. Happy monitoring! ???
| Back | FazBrowse Home | New Git URL |