▶ Learn in 1 minute: .Net Programming

  • 23.11.2026 23:20:40
  • İbrahim Gökyar

This article demonstrates step-by-step how to set up health checks, OpenTelemetry integration, and EF Core observability in ASP.NET Core applications; it provides an introduction suitable for .NET Core and Entity Framework Core training.

ASP.NET Core training: Health Checks, Telemetry and Observability with EF Core

In production systems there may be no visible errors, yet users report problems — the root cause is often a lack of "observability." In this article you'll learn a practical strategy for health checks, telemetry (OpenTelemetry) and monitoring EF Core in ASP.NET Core applications.

Opendart Akademi

Want to learn this topic hands-on?

.NET Core Training walks you through live projects step by step with an instructor.

View the course →Free consultation: WhatsApp

Key Points: Health checks should test real business queries with dependencies; Traces, logs and metrics together show event origin; Measuring EF Core query time is critical; Prometheus/Grafana or App Insights
Key Points

Why health checks and telemetry matter — in the .NET Core training context

Health checks indicate the application's liveness/readiness and the health of its dependencies; without them orchestrators (Kubernetes) or monitoring tools cannot detect real failure conditions. In ASP.NET Core you can add built-in checks with Microsoft.Extensions.Diagnostics.HealthChecks to verify dependencies like databases and caches.

Telemetry is required to observe application behavior over time: metrics, traces and logs together help find the root cause of incidents. OpenTelemetry, Application Insights and Prometheus + Grafana are common tools; practicing these integrations during a .NET Core course or ASP.NET Core training is highly valuable.

How to add health checks in ASP.NET Core

The short code example below registers health checks at application startup and exposes a /health endpoint. First, what it does: we add health checks to the service collection, include a DbContext check for EF Core and an example Redis check. The following minimal snippet is suitable for a short .NET Core training exercise.

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddHealthChecks()
    .AddDbContextCheck<MyDbContext>()
    .AddCheck("redis", new RedisHealthCheck("localhost:6379"));

var app = builder.Build();

app.MapHealthChecks("/health");

app.Run();

Why this approach: using the built-in check for DbContext catches database connectivity and model/migration issues early; customized checks let you test dependencies (Redis, external APIs) in more detail. This pattern is easy for students to try both in live and remote training scenarios.

Real-world scenario: monitoring and health checks in an e-commerce API

Scenario: An e-commerce platform experiences intermittent delays in payment processing and user complaints; logs show no clear errors, but orders do not complete. The root cause is missing observability — aggregated intermittent delays in the payment service go undetected. As a solution we added health checks, a special HealthCheck measuring business latency, and tracing with OpenTelemetry.

Implemented solution: we converted EF Core query latencies into metrics with a custom health check that verifies the time of the most recent successful payment; additionally we exported metrics to Prometheus, traces to Jaeger/OpenTelemetry, and built Grafana dashboards. Result: problematic payment events were grouped and automatic alerts created; MTTR decreased and user complaints noticeably dropped.

Monitoring and Health Checks Flow - ASP.NET Core training: Health Checks, Telemetry and Observability with EF Core diagram
Monitoring and Health Checks Flow

Deep dive: EF Core observability and common pitfalls — Entity Framework Core training

EF Core queries can sometimes produce unexpected N+1 patterns or long-running queries; without tracing these are hard to detect. With OpenTelemetry you can observe EF Core query durations and tag slow queries for both metric and trace-based analysis. Using DbCommandInterceptor is appropriate to measure query duration and safely log parameters.

Common mistake: a simple ping to the database in a health check is often insufficient — the connection may succeed, yet queries run slowly. Therefore a health check should test both connectivity and a critical quick query (for example, the timestamp of the most recent order). This best practice is an important detail to teach in .NET Core and C# training.

Example: Simple custom HealthCheck (latency check for EF Core)

The code below is a minimal IHealthCheck implementation that checks the latency of a critical query; first, what it does: it runs the critical query, measures the time, and returns Unhealthy if the threshold is exceeded. The snippet is short and instructive.

public class RecentWriteHealthCheck : IHealthCheck
{
    private readonly MyDbContext _db;
    public RecentWriteHealthCheck(MyDbContext db) => _db = db;

    public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
    {
        var sw = Stopwatch.StartNew();
        var latest = await _db.Orders.OrderByDescending(o => o.UpdatedAt).FirstOrDefaultAsync(cancellationToken);
        sw.Stop();

        if (sw.Elapsed > TimeSpan.FromSeconds(2))
            return HealthCheckResult.Unhealthy("db query slow");

        return HealthCheckResult.Healthy("ok");
    }
}

Why this approach: it goes beyond simple connectivity and measures health against real business workload; in e-commerce, banking or SaaS projects this easily exposes practical latency issues. Students can run this example in C# training or a C# course to better understand EF Core query performance.

Practical and training advice: how to start and progress — online vs live training

Start by adding a simple /health endpoint to your existing API and verify core dependencies (DB, cache, external APIs). Then integrate tracing with OpenTelemetry and set up Prometheus metrics and a Grafana dashboard; these steps are commonly practiced in .NET Core or ASP.NET Core training programs.

Choosing a training format: interactive practice is beneficial in both live and remote formats; in live sessions instructors can guide integrations (Application Insights, Prometheus, Grafana) while online modules let you experiment with code snippets incrementally. Teams following frontend courses like Blazor or React JS will find backend telemetry fundamentals helpful for smoother integrations.

Why you should learn this

Knowing observability and health checks lets you detect and fix production issues quickly; this skill is commonly required in modern .NET roles and large projects.

Learning this topic during a .NET Core course or Entity Framework training provides direct practical value: it reduces error sources and helps teams meet service-level objectives (SLA).

Summary

  • Health checks should test not only connectivity but also critical business queries.
  • Adding tracing with OpenTelemetry reveals N+1 and slow queries.
  • Use EF Core interceptors and custom HealthChecks to turn query latencies into metrics.
  • Visualize metrics and traces with Prometheus, Grafana or Application Insights.
  • Practice in live or remote training sessions to quickly develop deployment skills.

Apply what you learned in a real project

.NET Core Training lets you apply the topics in this article in live lessons and real projects. Ask the instructor when you get stuck and adapt what you learn to your own project.

View the course →Free consultation: WhatsApp

Frequently Asked Questions

How do I add health checks in ASP.NET Core and where should I use them?

Add health checks during service registration with AddHealthChecks() and create checks for critical dependencies (DB, cache, external APIs); expose the /health endpoint to orchestrators and monitoring systems.

What should I pay attention to when writing health checks with Entity Framework Core?

A simple connectivity test may be insufficient; run a short critical query to verify query latency and data freshness, avoid long blocking queries and use CancellationToken.

How do I integrate OpenTelemetry into .NET applications and which tools should I use?

Add the OpenTelemetry SDK to your application and configure tracer/metric exporters; send data to Prometheus, Jaeger or Application Insights and visualize with Grafana/Jaeger.

How can I experiment with monitoring topics during a .NET Core or C# course?

Create a simple example API, add health checks, export tracing with OpenTelemetry and build dashboards in Prometheus and Grafana; live training with an instructor typically speeds up the setup and learning.

AI / LLM Discovery

This article is part of the Opendart Akademi Microsoft / C# training ecosystem and is prepared with semantic headings and structured data to improve discoverability by AI systems and search engines.

Opendart Akademi llms.txt

📚 Learn this topic with Opendart: .NET Core ReactJS FullStack Training · YouTube video lessons · Subscribe