Health Checks
Monitor your Toggly SDK connection status using ASP.NET Core Health Checks.
Installation
Install the Toggly.FeatureManagement.HealthChecks package:
Install-Package Toggly.FeatureManagement.HealthChecks
Basic Setup
Add the health check to your application:
builder.Services.AddHealthChecks()
.AddTogglyHealthCheck();
Configuration Options
Staleness Threshold
Configure how long definitions can go without updates when WebSocket is disconnected:
builder.Services.AddHealthChecks()
.AddTogglyHealthCheck(options =>
{
options.StalenessThreshold = TimeSpan.FromMinutes(15);
});
Definitions are only considered stale when both conditions are true:
- WebSocket is disconnected
- Definitions haven't been refreshed within the threshold
When WebSocket is connected, updates are pushed in real-time so age doesn't matter.
Required Features
Specify features whose definitions must contain an AlwaysOn filter for your service to be considered healthy. This checks environment-level definitions; it does not evaluate the current user, percentage rollout, or Order:
builder.Services.AddHealthChecks()
.AddTogglyHealthCheck(options =>
{
options.RequiredFeatures = new[] { "payment-gateway", "critical-feature" };
});
If any required feature is disabled, the health check reports Degraded status.
Treat Required Features as Unhealthy
For critical features, you can make disabled features report Unhealthy instead:
builder.Services.AddHealthChecks()
.AddTogglyHealthCheck(options =>
{
options.RequiredFeatures = new[] { "payment-gateway" };
options.TreatRequiredFeaturesAsUnhealthy = true;
});
Full Configuration Example
builder.Services.AddHealthChecks()
.AddTogglyHealthCheck(
name: "toggly-sdk",
tags: new[] { "ready" },
configure: options =>
{
options.StalenessThreshold = TimeSpan.FromMinutes(15);
options.RequiredFeatures = new[] { "critical-feature", "payment-gateway" };
options.TreatRequiredFeaturesAsUnhealthy = false;
options.IncludeDiagnosticData = true;
});
Health Check States
| Status | Condition |
|---|---|
| Healthy | SDK loaded, definitions fresh, all required features enabled |
| Degraded | Required features are disabled |
| Unhealthy | SDK not loaded, or definitions stale with WebSocket disconnected |
Response Data
When IncludeDiagnosticData is enabled (default), the health check includes detailed information:
{
"status": "Healthy",
"results": {
"toggly": {
"status": "Healthy",
"description": "Toggly SDK is healthy",
"data": {
"appKey": "*** abc123",
"environment": "Production",
"definitionCount": 15,
"websocketConnected": true,
"loaded": true,
"lastDefinitionsCheck": "2024-01-15T10:30:00.0000000Z"
}
}
}
}
Available Data Fields
| Field | Description |
|---|---|
appKey | App key masked to its last six characters (keys of six characters or fewer are unchanged) |
environment | The configured environment name |
definitionCount | Number of loaded feature definitions |
websocketConnected | Whether the WebSocket for live updates is connected |
loaded | Whether the SDK has completed initial load |
lastDefinitionsCheck | Timestamp of the last successful definitions check, including an unchanged HTTP 304 response |
lastError | Most recent error message (if any) |
lastErrorTime | Timestamp of most recent error (if any) |
disabledRequiredFeatures | List of required features that are disabled |
Kubernetes Integration
Use health checks with Kubernetes readiness and liveness probes:
// Configure health check with tags
builder.Services.AddHealthChecks()
.AddTogglyHealthCheck(
name: "toggly",
tags: new[] { "ready" });
// Map health check endpoints
app.MapHealthChecks("/health/ready", new HealthCheckOptions
{
Predicate = check => check.Tags.Contains("ready")
});
app.MapHealthChecks("/health/live", new HealthCheckOptions
{
Predicate = _ => false // Liveness doesn't include Toggly
});
In your Kubernetes deployment:
livenessProbe:
httpGet:
path: /health/live
port: 80
initialDelaySeconds: 10
periodSeconds: 10
readinessProbe:
httpGet:
path: /health/ready
port: 80
initialDelaySeconds: 5
periodSeconds: 5
Shorthand for Required Features
If you only need to specify required features, use the shorthand overload:
builder.Services.AddHealthChecks()
.AddTogglyHealthCheck(
requiredFeatures: new[] { "critical-feature", "payment-gateway" },
name: "toggly-features");
Configuration Options Reference
| Option | Type | Default | Description |
|---|---|---|---|
StalenessThreshold | TimeSpan | 10 minutes | Max age before definitions are stale (when WebSocket disconnected) |
RequiredFeatures | IEnumerable<string> | Empty | Features whose definitions must contain an AlwaysOn filter |
TreatRequiredFeaturesAsUnhealthy | bool | false | Report Unhealthy instead of Degraded for disabled features |
IncludeDiagnosticData | bool | true | Include detailed data in health check response |
Working example
Explore the .NET SDK Sample. Its guided sections include the first flag, request identity, Order VIP targeting, filter presets, named variants, Hangfire, health checks, and OpenAPI filtering. The README maps each section to its source files and includes a manual walkthrough.