< Summary

Information
Class: NexusLabs.Needlr.AgentFramework.Langfuse.LangfuseScoreFailureSink
Assembly: NexusLabs.Needlr.AgentFramework.Langfuse
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework.Langfuse/LangfuseScoreFailureSink.cs
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 44
Line coverage: 100%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_FailedCount()100%11100%
Record(...)75%44100%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework.Langfuse/LangfuseScoreFailureSink.cs

#LineLine coverage
 1namespace NexusLabs.Needlr.AgentFramework.Langfuse;
 2
 3/// <summary>
 4/// Applies a session's <see cref="LangfuseScoreFailureMode"/> to a failed score upload and tracks
 5/// how many uploads have failed. Shared by every scenario created from one session.
 6/// </summary>
 7internal sealed class LangfuseScoreFailureSink
 8{
 9    private readonly LangfuseScoreFailureMode _mode;
 10    private readonly Action<LangfuseScoreError>? _callback;
 11    private int _failedCount;
 12
 1613    public LangfuseScoreFailureSink(
 1614        LangfuseScoreFailureMode mode,
 1615        Action<LangfuseScoreError>? callback)
 16    {
 1617        _mode = mode;
 1618        _callback = callback;
 1619    }
 20
 21    /// <summary>Gets the cumulative number of score uploads that have failed.</summary>
 322    public int FailedCount => Volatile.Read(ref _failedCount);
 23
 24    /// <summary>
 25    /// Records a failed score upload. In <see cref="LangfuseScoreFailureMode.Strict"/> mode the
 26    /// originating exception is rethrown; otherwise the failure counter is incremented, the error
 27    /// callback (if any) is invoked, and control returns to the caller.
 28    /// </summary>
 29    /// <param name="scoreName">The name of the score that failed.</param>
 30    /// <param name="traceId">The destination trace id, if known.</param>
 31    /// <param name="exception">The failure.</param>
 32    public void Record(string scoreName, string? traceId, LangfuseException exception)
 33    {
 334        ArgumentNullException.ThrowIfNull(exception);
 35
 336        if (_mode == LangfuseScoreFailureMode.Strict)
 37        {
 138            throw exception;
 39        }
 40
 241        Interlocked.Increment(ref _failedCount);
 242        _callback?.Invoke(new LangfuseScoreError(scoreName, traceId, exception));
 243    }
 44}