AddTraxHealthCheck

Adds an ASP.NET Core health check that reports on the Trax store: queued work, running executions, failures in the last hour, and dead letters awaiting intervention. It reports the same numbers as the GraphQL health query, through one shared service.

Signature

namespace Trax.Api.Extensions;
 
public static class HealthCheckExtensions
{
    public static IHealthChecksBuilder AddTraxHealthCheck(
        this IHealthChecksBuilder builder,
        string name = "trax",
        params string[] tags
    );
}
ParameterTypeDefaultDescription
builderIHealthChecksBuilderThe builder AddHealthChecks() returns
namestring"trax"The health check's registration name
tagsstring[]noneTags for filtering in MapHealthChecks

Returns: the IHealthChecksBuilder, for chaining.

What it reports

StatusWhen
HealthyNo dead letter awaits intervention and at most 10 executions failed in the last hour. Description: "All systems operational".
DegradedAny dead letter awaits intervention, or more than 10 executions failed in the last hour. Description: "Elevated failures or unresolved dead letters".

The check itself never returns Unhealthy. If the store cannot be queried, the exception propagates and ASP.NET Core reports the check's failure status, Unhealthy by default.

Each result carries the counts as data:

KeyMeaning
queueDepthWork queue entries queued and not yet dispatched
inProgressExecutions running now
failedLastHourExecutions that failed with an end time in the last hour
deadLettersDead letters awaiting intervention

The counts are read from the store on every call; nothing is cached.

Requirements

The check resolves ITraxHealthService, which AddTraxApi registers, and AddTraxGraphQL calls AddTraxApi. On a host with neither, the check fails when it runs because the service cannot be resolved. A data provider (UsePostgres, UseSqlite or UseInMemory) must be configured.

ITraxHealthService (Trax.Api.Services.HealthCheck, one method: Task<HealthStatus> GetHealthAsync(CancellationToken ct = default)) is hidden from completion. To change how health is computed for both the check and the GraphQL query, register your own implementation after AddTraxGraphQL.

Example

builder.Services.AddTrax(trax => trax
    .AddEffects(effects => effects.UsePostgres(connectionString))
    .AddMediator(typeof(Program).Assembly)
    .AddScheduler());
 
builder.Services.AddTraxGraphQL();
builder.Services.AddHealthChecks().AddTraxHealthCheck(tags: "ready");
 
var app = builder.Build();
app.MapHealthChecks("/trax/health");

For the scheduler's own liveness, which fails when the dispatcher stops completing cycles, see AddTraxSchedulerLiveness.

Package

dotnet add package Trax.Api

Trax.Api.GraphQL depends on it, so a GraphQL host already has it.