Skip to content

Commit

Permalink
Add health checks to OTLP service (#18)
Browse files Browse the repository at this point in the history
A new constant, ExposeHealthChecks, was added to OtlpLiterals.cs to allow the toggling of health checks through the environment variable "OTEL_EXPOSE_HEALTHCHECKS". Also, MapDefaultEndpoints method was added to OtlpServiceExtensions.cs to map health check endpoints if ExposeHealthChecks is enabled.
  • Loading branch information
prom3theu5 authored Jul 10, 2024
1 parent 7d9405e commit b0d048c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/SimCube.Aspire/Features/Otlp/OtlpLiterals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public static class OtlpLiterals
public const string Headers = "OTEL_EXPORTER_OTLP_HEADERS";
public const string ResourceAttributes = "OTEL_RESOURCE_ATTRIBUTES";
public const string ServiceName = "OTEL_SERVICE_NAME";
}
public const string ExposeHealthChecks = "OTEL_EXPOSE_HEALTHCHECKS";
}
15 changes: 15 additions & 0 deletions src/SimCube.Aspire/Features/Otlp/OtlpServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ public static LoggerConfiguration GetLoggerConfiguration(this IConfiguration con

return config;
}

public static void MapDefaultEndpoints(this WebApplication app)
{
if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("OTEL_EXPOSE_HEALTHCHECKS")))
{
return;
}

app.MapHealthChecks("/health");

app.MapHealthChecks("/alive", new()
{
Predicate = r => r.Tags.Contains("live")
});
}

private static void ConfigureSerilog(this IHostApplicationBuilder builder)
{
Expand Down

0 comments on commit b0d048c

Please sign in to comment.