Skip to content

IPipelineMetrics

NexusLabs.Needlr.AgentFramework

NexusLabs.Needlr.AgentFramework.Diagnostics

IPipelineMetrics Interface

Records pipeline-shape execution metrics for observability. The default implementation emits System.Diagnostics.Metrics.Meter counters / histograms and ActivitySource activities compatible with OpenTelemetry. Sibling of IAgentMetrics — that interface scopes to per-agent-run signals; this one scopes to per-pipeline and per-stage signals emitted by SequentialPipelineRunner.

public interface IPipelineMetrics

Remarks

Registered via DI — consumers can replace with a no-op (NexusLabs.Needlr.AgentFramework.Diagnostics.NoOpPipelineMetrics) or a custom implementation. The runner resolves IPipelineMetrics from DI and calls these methods at the appropriate emission points; consumers do not call them directly.

If OpenTelemetry is wired in the host (e.g., via AddOpenTelemetry()), these metrics are exported automatically — no Needlr-specific configuration required beyond ensuring the configured meter / activity-source name is added to the OpenTelemetry pipeline.

Properties

IPipelineMetrics.ActivitySource Property

Gets the ActivitySource the runner uses to create pipeline.run and pipeline.stage spans. Exported via OpenTelemetry when a listener is registered against the configured source name.

System.Diagnostics.ActivitySource ActivitySource { get; }

Property Value

System.Diagnostics.ActivitySource

Methods

IPipelineMetrics.RecordPipelineCompleted(string, bool, TimeSpan) Method

Records that a pipeline run has completed. Called once at the end of every pipeline invocation, on both success and failure paths.

void RecordPipelineCompleted(string pipelineName, bool succeeded, System.TimeSpan duration);

Parameters

pipelineName System.String

The pipeline's stable identifier (see RecordPipelineStarted(string)).

succeeded System.Boolean

Whether all stages completed successfully.

duration System.TimeSpan

Wall-clock duration of the entire pipeline run.

IPipelineMetrics.RecordPipelineStarted(string) Method

Records that a pipeline run has started. Called once at the beginning of every pipeline invocation.

void RecordPipelineStarted(string pipelineName);

Parameters

pipelineName System.String

The pipeline's stable identifier — used as the pipeline_name tag on every metric this run emits. Sourced from SequentialPipelineOptions.PipelineName when supplied, otherwise from the progress reporter's WorkflowId.

IPipelineMetrics.RecordStageCompleted(string, IAgentStageResult, TimeSpan) Method

Records that a single pipeline stage has completed. Called once per stage (skipped, failed, succeeded, partial-failed) immediately after the stage's IAgentStageResult is constructed.

void RecordStageCompleted(string pipelineName, NexusLabs.Needlr.AgentFramework.Diagnostics.IAgentStageResult stage, System.TimeSpan duration);

Parameters

pipelineName System.String

The pipeline's stable identifier (see RecordPipelineStarted(string)).

stage IAgentStageResult

The completed stage's result; the implementation derives per-stage tag values (stage_name, phase_name, outcome, termination_cause) and emits per-token-kind / per-tool-failure instruments from IAgentRunDiagnostics.

duration System.TimeSpan

Wall-clock duration of this stage's execution. System.TimeSpan.Zero for skipped stages (no work was done).