< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Health.DelegateProbe
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Health/DelegateProbe.cs
Tag: Kestrun/Kestrun@2d87023b37eb91155071c91dd3d6a2eeb3004705
Line coverage
0%
Covered lines: 0
Uncovered lines: 22
Coverable lines: 22
Total lines: 52
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 10/13/2025 - 16:52:37 Line coverage: 0% (0/22) Branch coverage: 0% (0/6) Total lines: 52 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e 10/13/2025 - 16:52:37 Line coverage: 0% (0/22) Branch coverage: 0% (0/6) Total lines: 52 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)0%110100%
get_Name()100%210%
get_Tags()100%210%
get_Logger()100%210%
CheckAsync()0%2040%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Health/DelegateProbe.cs

#LineLine coverage
 1using Serilog.Events;
 2
 3namespace Kestrun.Health;
 4
 5/// <summary>
 6/// Simple <see cref="IProbe"/> implementation that delegates execution to a user-supplied asynchronous function.
 7/// </summary>
 08internal sealed class DelegateProbe(string name, IEnumerable<string>? tags, Func<CancellationToken, Task<ProbeResult>> c
 9{
 010    private readonly Func<CancellationToken, Task<ProbeResult>> _callback = callback ?? throw new ArgumentNullException(
 11
 12    /// <inheritdoc />
 013    public string Name { get; } = string.IsNullOrWhiteSpace(name)
 014        ? throw new ArgumentException("Probe name cannot be null or empty.", nameof(name))
 015        : name;
 16
 17    /// <inheritdoc />
 018    public string[] Tags { get; } = tags?.Where(static t => !string.IsNullOrWhiteSpace(t))
 019                                       .Select(static t => t.Trim())
 020                                       .Distinct(StringComparer.OrdinalIgnoreCase)
 021                                       .ToArray() ?? [];
 22
 23    /// <inheritdoc />
 024    public Serilog.ILogger Logger { get; init; } = logger ?? Serilog.Log.ForContext("Probe", name);
 25
 26    /// <inheritdoc />
 27    public async Task<ProbeResult> CheckAsync(CancellationToken ct = default)
 28    {
 29        try
 30        {
 031            if (Logger.IsEnabled(LogEventLevel.Debug))
 32            {
 033                Logger.Debug("DelegateProbe {Probe} starting", Name);
 34            }
 035            var result = await _callback(ct).ConfigureAwait(false);
 036            if (Logger.IsEnabled(LogEventLevel.Debug))
 37            {
 038                Logger.Debug("DelegateProbe {Probe} completed status={Status}", Name, result.Status);
 39            }
 040            return result;
 41        }
 042        catch (OperationCanceledException) when (ct.IsCancellationRequested)
 43        {
 044            return new ProbeResult(ProbeStatus.Degraded, "Canceled");
 45        }
 046        catch (Exception ex)
 47        {
 048            Logger.Error(ex, "DelegateProbe {Probe} failed", Name);
 049            return new ProbeResult(ProbeStatus.Unhealthy, $"Exception: {ex.Message}");
 50        }
 051    }
 52}