Health Checks

The IEvangelist.Azure.CosmosRepository.AspNetCore package adds support for AspNet Core Health Checks using the HealthChecks.CosmosDb package.

Setup

To configure Cosmos DB health checks:

services.AddHealthChecks().AddCosmosRepository();

By default, this will scan all of the assemblies in your solution to locate the container names for each of your IItem types. To refine this, and potentially reduce startup times, pass in the Assemblies containing your IItem types:

services.AddHealthChecks().AddCosmosRepository(assemblies: typeof(ExampleItem).Assembly);

Alternatively, use the override to provide your own AzureCosmosDbHealthCheckOptions and configure the Containers to check:

services.AddHealthChecks().AddCosmosRepository(optionsFactory: sp => new AzureCosmosDbHealthCheckOptions
{
    DatabaseId = "my-database",
    ContainerIds = new[] { "Container1", "Container2" }
});

Use optionsFactory: null to retain the default behaviour of the HealthChecks.CosmosDb package, and only call CosmosClient.ReadAccountAsync().

services.AddHealthChecks().AddCosmosRepository(optionsFactory: null);

The Cosmos Repository Health package supports all of the existing functionality of Health Checks, such as failureStatus and tags, see the Microsoft documentation for configuration details.

Don’t forget to map the health endpoint with:

app.MapHealthChecks("/healthz");