
- ASP.NET Core's built-in observability features
- Detailed setup
- Examples of real-world coding for tracking, logging, and metrics
- Alerts, dashboards, and production preparedness
Observability is the ability to understand the internal state of your application from external outputs like metrics, logs, and traces.
Core Observability Components
your application's internal state from external outputs such asMetrics – Quantitative data (request rate, latency, errors).
Logs – Detailed events or errors with structured information.as Metrics
Traces – End-to-end visibility of requests across services.
Proper observability ensures you can detect and diagnose issues without guessing .
Built-In Observability Features in ASP.NET Core
ASP.NET Core now ships with rich diagnostics:
HTTP request counts and durations
Active requests
Failed requests (4xx / 5xx)
Connection, TLS, and runtime metrics (CPU, memory, GC)
These features reduce the need for heavy custom instrumentation and integrate easily with Prometheus, Grafana, and Azure Monitor.
Step-by-Step Setup of Observability
1. Create or Open Your ASP.NET Core App
2. Add Required NuGet Packages
3. Configure OpenTelemetry in Program.cs
Your app now exposes production-ready metrics at
/metrics.
Real-World Coding Examples
These examples illustrate practical observability in production scenarios.
Example 1: Track API Usage (Business Metric)
Scenario: Track how many orders your API receives per minute for business insight.
Example 2: Measure Request Duration for a Specific Endpoint
Scenario: Measure performance of heavy endpoints like inventory queries or report generation.
Example 3: Track Failures with Custom Counter
Scenario: Monitor payment failures in real-time for alerting or retries.
Example 4: Add Distributed Tracing for Downstream Calls
Scenario: Trace latency across external API calls to identify bottlenecks.
Dashboards and Alerts
Prometheus & Grafana
For dashboards and alerts we can use open sourced, self-hosted, cloud-friendly observability tools Prometheus and Grafana. They work on-prem, cloud, hybrid, and air-gapped systems. Cloud providers offer managed versions.
Dashboard Panels:
Request rate (
http_server_request_duration_seconds_count)Latency P95 (
histogram_quantile(0.95, rate(...)))Error rate (
rate(http_server_request_duration_seconds_count{status_code=~"5.."}[1m]))
Alerts:
High error rate
High latency
CPU/memory spikes
Include service name, severity, and dashboard links in every alert.
Before going live, ensure:
Metrics endpoint exposes system and business metrics
Structured logging with correlation IDs is enabled
Distributed tracing is enabled for all incoming/outgoing requests
Health checks and readiness probes are configured
Dashboards visualize key metrics and errors
Alerts are actionable and tested
Deployment markers and versions are visible
Production-ready apps answer: "What broke, why, and how badly — using metrics, logs, and traces alone."
Key Takeaways
ASP.NET Core's first-class observability enables developers to monitor apps confidently in production. By combining metrics, logs, tracing, dashboards, and alerts, you can proactively detect and resolve issues, optimize performance, and ensure your applications are reliable.
Observability is no longer optional — it's essential. Start implementing it from day one and make your app production-ready.
Happy Coding!
I write about modern C#, .NET, and real-world development practices. Follow me on C# Corner for regular insights, tips, and deep dives.










