Skip to content

IAgentMetrics

NexusLabs.Needlr.AgentFramework

NexusLabs.Needlr.AgentFramework.Diagnostics

IAgentMetrics Interface

Records agent execution metrics for observability. The default implementation emits System.Diagnostics.Metrics.Meter counters/histograms and System.Diagnostics.ActivitySource activities compatible with OpenTelemetry.

public interface IAgentMetrics

Remarks

Registered via DI — consumers can replace with a no-op or custom implementation. The diagnostics middleware automatically calls these methods; tools and orchestrators do not need to call them directly.

If OpenTelemetry is wired in the host (e.g., via AddOpenTelemetry()), these metrics are exported automatically. No needlr-specific configuration required.

Properties

IAgentMetrics.ActivitySource Property

Gets the System.Diagnostics.ActivitySource for creating distributed tracing spans. Middleware uses this to create System.Diagnostics.Activity instances for agent runs, tool calls, and chat completions that are exported via OpenTelemetry when a listener is registered.

System.Diagnostics.ActivitySource ActivitySource { get; }

Property Value

System.Diagnostics.ActivitySource

Methods

IAgentMetrics.RecordChatCompletion(string, TimeSpan, bool, string) Method

Records a completed LLM chat completion call.

void RecordChatCompletion(string model, System.TimeSpan duration, bool succeeded, string? agentName=null);

Parameters

model System.String

The model identifier.

duration System.TimeSpan

How long the completion took.

succeeded System.Boolean

Whether the completion succeeded.

agentName System.String

The name of the agent that triggered the completion, or null if unknown.

IAgentMetrics.RecordRunCompleted(IAgentRunDiagnostics) Method

Records that an agent run has completed with the given diagnostics.

void RecordRunCompleted(NexusLabs.Needlr.AgentFramework.Diagnostics.IAgentRunDiagnostics diagnostics);

Parameters

diagnostics IAgentRunDiagnostics

The completed run's diagnostics.

IAgentMetrics.RecordRunStarted(string) Method

Records that an agent run has started.

void RecordRunStarted(string agentName);

Parameters

agentName System.String

The name of the agent.

IAgentMetrics.RecordToolCall(string, TimeSpan, bool, string) Method

Records a completed tool call.

void RecordToolCall(string toolName, System.TimeSpan duration, bool succeeded, string? agentName=null);

Parameters

toolName System.String

The tool that was invoked.

duration System.TimeSpan

How long the tool call took.

succeeded System.Boolean

Whether the tool call succeeded.

agentName System.String

The name of the agent that invoked the tool, or null if unknown.