< Summary

Information
Class: NexusLabs.Needlr.AgentFramework.Diagnostics.ToolMetricsAccessor
Assembly: NexusLabs.Needlr.AgentFramework
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework/Diagnostics/ToolMetricsAccessor.cs
Line coverage
100%
Covered lines: 5
Uncovered lines: 0
Coverable lines: 5
Total lines: 31
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
AttachMetric(...)100%22100%
GetCurrentMetrics()100%11100%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework/Diagnostics/ToolMetricsAccessor.cs

#LineLine coverage
 1using System.Collections.Concurrent;
 2
 3namespace NexusLabs.Needlr.AgentFramework.Diagnostics;
 4
 5/// <summary>
 6/// <see cref="AsyncLocal{T}"/>-backed implementation of <see cref="IToolMetricsAccessor"/>.
 7/// The diagnostics function-calling middleware establishes and clears the metrics dict
 8/// per tool invocation.
 9/// </summary>
 10/// <remarks>
 11/// Uses <see cref="ConcurrentDictionary{TKey,TValue}"/> so that tool functions which
 12/// fan out concurrent work via <c>Task.WhenAll</c> can safely call
 13/// <see cref="AttachMetric"/> from multiple threads.
 14/// </remarks>
 15internal sealed class ToolMetricsAccessor : IToolMetricsAccessor
 16{
 117    internal static readonly AsyncLocal<ConcurrentDictionary<string, object?>?> CurrentToolMetrics = new();
 18
 19    /// <inheritdoc />
 20    public void AttachMetric(string key, object? value)
 21    {
 10622        if (CurrentToolMetrics.Value is { } metrics)
 23        {
 10524            metrics[key] = value;
 25        }
 10626    }
 27
 28    /// <inheritdoc />
 29    public IReadOnlyDictionary<string, object?>? GetCurrentMetrics() =>
 530        CurrentToolMetrics.Value;
 31}