Skip to main content

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);
});
info

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​

StatusCondition
HealthySDK loaded, definitions fresh, all required features enabled
DegradedRequired features are disabled
UnhealthySDK 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​

FieldDescription
appKeyApp key masked to its last six characters (keys of six characters or fewer are unchanged)
environmentThe configured environment name
definitionCountNumber of loaded feature definitions
websocketConnectedWhether the WebSocket for live updates is connected
loadedWhether the SDK has completed initial load
lastDefinitionsCheckTimestamp of the last successful definitions check, including an unchanged HTTP 304 response
lastErrorMost recent error message (if any)
lastErrorTimeTimestamp of most recent error (if any)
disabledRequiredFeaturesList 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​

OptionTypeDefaultDescription
StalenessThresholdTimeSpan10 minutesMax age before definitions are stale (when WebSocket disconnected)
RequiredFeaturesIEnumerable<string>EmptyFeatures whose definitions must contain an AlwaysOn filter
TreatRequiredFeaturesAsUnhealthyboolfalseReport Unhealthy instead of Degraded for disabled features
IncludeDiagnosticDatabooltrueInclude 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.