Rig.TUnit.Observability.Metrics 0.1.0-beta.2

This is a prerelease version of Rig.TUnit.Observability.Metrics.
dotnet add package Rig.TUnit.Observability.Metrics --version 0.1.0-beta.2
                    
NuGet\Install-Package Rig.TUnit.Observability.Metrics -Version 0.1.0-beta.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Rig.TUnit.Observability.Metrics" Version="0.1.0-beta.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Rig.TUnit.Observability.Metrics" Version="0.1.0-beta.2" />
                    
Directory.Packages.props
<PackageReference Include="Rig.TUnit.Observability.Metrics" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Rig.TUnit.Observability.Metrics --version 0.1.0-beta.2
                    
#r "nuget: Rig.TUnit.Observability.Metrics, 0.1.0-beta.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Rig.TUnit.Observability.Metrics@0.1.0-beta.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Rig.TUnit.Observability.Metrics&version=0.1.0-beta.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Rig.TUnit.Observability.Metrics&version=0.1.0-beta.2&prerelease
                    
Install as a Cake Tool

Rig.TUnit.Observability.Metrics

In-process MeterListener-based metrics capture with MetricAssert and TagCardinalityGuard.

What this package is

A metrics testing fixture for System.Diagnostics.Metrics. MetricsFixture creates a MeterListener wired to a named Meter — your production code emits via the real Meter.CreateCounter<T> / etc., and the fixture records every sample for assertion. TagCardinalityGuard is the novel piece: it asserts that a given tag's distinct-value count stays within a budget, because unbounded cardinality is the #1 cause of TSDB bill shock.

When to use it

  • Asserting counter / histogram / gauge increments match design expectations.
  • Regression-guarding against cardinality explosions.
  • Verifying tag-name consistency across instrumentation sites.
  • Not for: E2E tests hitting a real Prometheus / OTLP collector — those need a separate integration flow.

Prerequisites

  • .NET 10 SDK
  • System.Diagnostics.DiagnosticSource (in-box)

Quick start

using System.Diagnostics.Metrics;
using Rig.TUnit.Observability.Metrics.Fixtures;
using Rig.TUnit.Observability.Metrics.Options;

await using var fx = new MetricsFixture(new MetricsFixtureOptions
{
    MeterName = "orders.service",
});
await fx.InitializeAsync();

using var meter = new Meter("orders.service");
var counter = meter.CreateCounter<long>("orders.placed");
counter.Add(1);

Options

Property Type Default Description
MeterName string "Rig.TUnit.Metrics" Meter.Name to listen on
MaxTagCardinality int 100 Cardinality budget enforced by TagCardinalityGuard
IncludeHistograms bool true Capture histogram samples

Fixture + helper APIs

  • Rig.TUnit.Observability.Metrics.Fixtures.MetricsFixture
  • Rig.TUnit.Observability.Metrics.Options.MetricsFixtureOptions
  • Rig.TUnit.Observability.Metrics.Builder.MetricsRigBuilder
  • Rig.TUnit.Observability.Metrics.Assertions.MetricAssert
  • Rig.TUnit.Observability.Metrics.Helpers.TagCardinalityGuard

Per-test isolation

Each fixture owns its MeterListener; listeners are per-fixture so parallel tests don't cross-contaminate samples. MeterName includes IsolationKey when using the default wiring.

Parallelism + performance

  • Fixture construction: ~1 ms.
  • Per-sample capture: ~500 ns.
  • Safe under full parallelism.

Troubleshooting

  • MetricAssert.Counter(…).Sum() returns 0MeterListener started AFTER the Meter was created; ensure the fixture initialises before the code under test instantiates its meter.
  • Histograms return empty distribution — set IncludeHistograms=true (default true) and confirm the histogram is actually recorded, not just created.

See docs/troubleshooting.md#metrics.

Provider quirks + edge cases

  • TagCardinalityGuard.EnsureWithinBudget is a pure predicate — call it in test teardown or at assertion time, not in production code.
  • Multiple meters can share a name; the fixture listens on ALL of them matching the MeterName.

Benchmarks

See MetricsBenchmarks.cs; baseline in benchmarks/baseline-005.json.

License

MIT. See LICENSE.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Rig.TUnit.Observability.Metrics:

Package Downloads
Rig.TUnit.All

Meta-package containing every Rig.TUnit.* package. DISCOURAGED — prefer per-feature or per-stack meta-packages (Rig.TUnit, Rig.TUnit.Microservices).

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0-beta.2 44 4/27/2026
0.0.0-alpha.0.14 50 4/26/2026