Orchard Core Health Checks - Prompt Templates
Expose Tenant Health Checks
You are an Orchard Core expert. Generate health endpoint configuration and ASP.NET Core health check integrations for Orchard Core.
Guidelines
- Enable the
OrchardCore.HealthChecksfeature. The module has no declared feature dependencies. - The feature registers ASP.NET Core health check services with
services.AddHealthChecks(). - By default, the health endpoint is
/health/live, relative to the tenant host and URL prefix. Configure it per tenant through theOrchardCore:HealthChecksconfiguration section (formerlyOrchardCore_HealthChecks). - The feature has no admin UI or site settings, and it registers no check itself. With no checks registered, the endpoint reports
Healthy.OrchardCore.RedisandOrchardCore.Smscontribute checks when they are enabled with Health Checks. - The endpoint does not require authentication and runs every registered check; the module does not filter by tag.
- Set
ShowDetailstofalsefor a minimal standard health response. Set it totrueonly for protected operational endpoints that may expose dependency information. - With details enabled, the module uses
IHealthChecksResponseWriterand returns JSON with overall status, duration, and each check's name, status, and description. - With
ShowDetails: false, the standard ASP.NET Core response returns200for Healthy and Degraded and503for Unhealthy. With details enabled, every status returns200, so monitors must parse the JSONStatus. Both modes disable response caching. - The route and writer are chosen when the tenant pipeline is built; reload the tenant or restart after changing the settings.
- The endpoint is mapped through endpoint routing, so an
Endpointpolicy fromorchardcore-rate-limitson the health path can throttle probes. - Implement
Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheckfor custom dependencies and register it usingIHealthChecksBuilder. - Keep health checks fast, cancellation-aware, and free of side effects.
- All recipe JSON must be wrapped in the root
{ "steps": [...] }format. - All C# classes must use the
sealedmodifier, except View Models.
Enabling Health Checks
{
"steps": [
{
"name": "Feature",
"enable": [
"OrchardCore.HealthChecks"
],
"disable": []
}
]
}
Tenant Configuration
The module binds HealthChecksOptions from OrchardCore:HealthChecks.
{
"OrchardCore": {
"HealthChecks": {
"Url": "/health/live",
"ShowDetails": false
}
}
}
OrchardCore__HealthChecks__Url=/health/live
OrchardCore__CustomerA__HealthChecks__Url=/health/ready
The second variable targets only the CustomerA tenant.
| Option | Default | Description |
|---|---|---|
| Url | /health/live | Tenant health endpoint path. |
| ShowDetails | false | Enables the detailed JSON response writer. |
Use the shell or tenant configuration source appropriate to the hosting model so the settings apply to the intended tenant.
Registering a Custom Health Check
Register custom checks in a module startup class. The Health Checks feature already calls AddHealthChecks; calling it again returns the same builder for adding checks. Use [RequireFeatures("OrchardCore.HealthChecks")] so the registration loads only when the endpoint exists, or declare the feature as a dependency.
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using OrchardCore.Modules;
namespace MyModule;
[RequireFeatures("OrchardCore.HealthChecks")]
public sealed class Startup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services
.AddHealthChecks()
.AddCheck<InventoryHealthCheck>("inventory");
}
}
using Microsoft.Extensions.Diagnostics.HealthChecks;
namespace MyModule;
public sealed class InventoryHealthCheck : IHealthCheck
{
private readonly IInventoryClient _inventoryClient;
public InventoryHealthCheck(IInventoryClient inventoryClient)
{
_inventoryClient = inventoryClient;
}
public async Task<HealthCheckResult> CheckHealthAsync(
HealthCheckContext context,
CancellationToken cancellationToken = default)
{
var isAvailable = await _inventoryClient.IsAvailableAsync(cancellationToken);
return isAvailable
? HealthCheckResult.Healthy("Inventory service is reachable.")
: HealthCheckResult.Unhealthy("Inventory service is unavailable.");
}
}
Detailed Response Format
When ShowDetails is true, DefaultHealthChecksResponseWriter produces JSON shaped like:
{
"Status": "Healthy",
"Duration": "00:00:00.0123456",
"HealthChecks": [
{
"Name": "inventory",
"Status": "Healthy",
"Description": "Inventory service is reachable."
}
]
}
The response writer uses HealthReport.TotalDuration and every HealthReportEntry from the health report.
Replacing the Response Writer
Register a custom scoped IHealthChecksResponseWriter only when the detailed contract must change.
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using OrchardCore.HealthChecks.Services;
namespace MyModule;
public sealed class ProbeResponseWriter : IHealthChecksResponseWriter
{
public async Task WriteResponseAsync(HttpContext context, HealthReport report)
{
context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new
{
status = report.Status.ToString(),
});
}
}
services.Replace(ServiceDescriptor.Scoped<IHealthChecksResponseWriter, ProbeResponseWriter>());
The writer is only used when ShowDetails is true; compact mode keeps the ASP.NET Core default writer.
Probe Design
- Use
/health/livefor a lightweight process liveness check. - Add dependency checks deliberately for readiness-style monitoring.
- Do not expose detailed dependency names and descriptions on a public internet endpoint.
- Set probe timeouts in the hosting platform and honor the
CancellationTokenin custom checks. - Do not use a health check to perform migrations, warm caches, or repair data.
- The endpoint is anonymous. Restrict it with network policy or a reverse proxy when it should not be public, especially with
ShowDetailsenabled. - For separate liveness and readiness semantics, map additional filtered endpoints in module code; this endpoint always runs every check.
Troubleshooting
| Symptom | Check |
|---|---|
| Endpoint is missing (404) | Enable OrchardCore.HealthChecks for the tenant and include the tenant host and URL prefix. |
| Wrong endpoint path | Check OrchardCore:HealthChecks:Url in tenant configuration, then reload the tenant. |
| JSON details are absent | Set ShowDetails to true. |
| Unhealthy response has HTTP 200 | This is expected with detailed output; evaluate the JSON Status. |
| Custom check never runs | Verify it is registered with AddHealthChecks().AddCheck in a feature enabled on the same tenant. |
| Probe returns 429 | A Rate Limits policy (global or endpoint) is throttling the probe; exclude or raise its budget. |
Upgrading from 3.x
- Rename the
OrchardCore_HealthCheckssection toOrchardCore:HealthChecks(environment variableOrchardCore__HealthChecks__Url). The old name still works but is deprecated. - In a tenant
App_Data/Sites/{TenantName}/appsettings.json, use a rootHealthCheckssection. RedisHealthChecknow takes anIRedisServiceinstead of anIServiceProvider. Register it withAddRedisCheck()rather than constructing it. When the Redis configuration is missing or invalid, the check reportsUnhealthy("Couldn't connect to the Redis server…") instead of sayingIRedisServiceisn't registered.