< Summary

Information
Class: NexusLabs.Needlr.AgentFramework.Diagnostics.AgentFrameworkMetricsOptions
Assembly: NexusLabs.Needlr.AgentFramework
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework/Diagnostics/AgentFrameworkMetricsOptions.cs
Line coverage
75%
Covered lines: 3
Uncovered lines: 1
Coverable lines: 4
Total lines: 58
Line coverage: 75%
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
get_MeterName()100%11100%
get_ActivitySourceName()100%11100%
get_ChatCompletionActivityMode()100%210%
get_ResolvedActivitySourceName()100%22100%

File(s)

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

#LineLine coverage
 1namespace NexusLabs.Needlr.AgentFramework.Diagnostics;
 2
 3/// <summary>
 4/// Configuration options for the agent framework's OpenTelemetry metrics and tracing.
 5/// </summary>
 6/// <remarks>
 7/// <para>
 8/// Consumers that have existing dashboards keyed to a specific meter name (e.g.,
 9/// <c>"BrandGhost.Agents"</c>) can set <see cref="MeterName"/> to match, avoiding a
 10/// dashboard migration when adopting Needlr's <see cref="IAgentMetrics"/>.
 11/// </para>
 12/// <para>
 13/// Configure via the syringe:
 14/// <code>
 15/// .UsingAgentFramework(af => af
 16///     .ConfigureMetrics(o => o.MeterName = "MyApp.Agents"))
 17/// </code>
 18/// </para>
 19/// </remarks>
 20[DoNotAutoRegister]
 21public sealed class AgentFrameworkMetricsOptions
 22{
 23    /// <summary>
 24    /// The name used for the <see cref="System.Diagnostics.Metrics.Meter"/> that emits
 25    /// counters and histograms. Defaults to <c>"NexusLabs.Needlr.AgentFramework"</c>.
 26    /// </summary>
 25827    public string MeterName { get; set; } = "NexusLabs.Needlr.AgentFramework";
 28
 29    /// <summary>
 30    /// The name used for the <see cref="System.Diagnostics.ActivitySource"/> that emits
 31    /// distributed tracing spans. Defaults to <see cref="MeterName"/> when
 32    /// <see langword="null"/>.
 33    /// </summary>
 9834    public string? ActivitySourceName { get; set; }
 35
 36    /// <summary>
 37    /// Controls how Needlr's diagnostics middleware creates
 38    /// <see cref="System.Diagnostics.Activity"/> spans for chat completion calls.
 39    /// </summary>
 40    /// <remarks>
 41    /// <para>
 42    /// When MEAI's <c>UseOpenTelemetry()</c> or MAF's <c>WithOpenTelemetry()</c> is
 43    /// also active, both Needlr and the upstream middleware create spans for the same
 44    /// chat completion call. Set this to
 45    /// <see cref="ChatCompletionActivityMode.EnrichParent"/> to avoid duplicate spans —
 46    /// Needlr will add its tags (sequence number, char counts, agent name) to the
 47    /// existing parent <c>gen_ai.*</c> activity instead of creating a new one.
 48    /// </para>
 49    /// <para>
 50    /// Tool call activities (<c>agent.tool</c>) are not affected by this setting —
 51    /// they are always created because neither MEAI nor MAF produces per-tool-call spans.
 52    /// </para>
 53    /// </remarks>
 054    public ChatCompletionActivityMode ChatCompletionActivityMode { get; set; } =
 55        ChatCompletionActivityMode.Always;
 56
 8757    internal string ResolvedActivitySourceName => ActivitySourceName ?? MeterName;
 58}