Simulate 0.0.5

dotnet add package Simulate --version 0.0.5
                    
NuGet\Install-Package Simulate -Version 0.0.5
                    
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="Simulate" Version="0.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Simulate" Version="0.0.5" />
                    
Directory.Packages.props
<PackageReference Include="Simulate" />
                    
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 Simulate --version 0.0.5
                    
#r "nuget: Simulate, 0.0.5"
                    
#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 Simulate@0.0.5
                    
#: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=Simulate&version=0.0.5
                    
Install as a Cake Addin
#tool nuget:?package=Simulate&version=0.0.5
                    
Install as a Cake Tool

Simulate

Simulate is a lightweight and extensible .NET simulation framework designed for running and measuring concurrent task executions. It supports structured logging, metrics, and tracing to help you analyze simulation outcomes and performance with full observability.

โœจ Features

  • ๐Ÿ“ˆ Run simulations with a configurable duration, copy count, and increasing rate
  • ๐ŸŽฏ Supports:
    • System.Diagnostics.Metrics for metrics
    • System.Diagnostics.ActivitySource for tracing
    • ILogger for structured logging
  • ๐Ÿงช Built-in result tracking with thread-safe success/failure counts
  • ๐Ÿ“Š Emits OpenTelemetry-compatible metrics and spans
  • โš™๏ธ Easy to test and extend

๐Ÿ“ฆ Installation

Add the package via NuGet:

dotnet add package Simulate

๐Ÿš€ Usage

var simulation = await new Simulation("example", async logger =>
{
    logger.LogInformation("Relevant information");
    await Task.Delay(100); // Simulated task
    return new Result(true); // Simulation result
})
.RunFor(duration: TimeSpan.FromSeconds(5), copies: 5, rate: 2.0)
.Run();

Console.WriteLine($"Successes: {simulation.Results.Successes}");
Console.WriteLine($"Failures: {simulation.Results.Failures}");

๐Ÿ“Š Metrics

Simulate emits three main metrics:

Metric Name Type Description
simulations.ok Counter Total number of successful runs
simulations.fail Counter Total number of failed runs
simulations.duration Histogram Time taken per simulation (ms)

All metrics are tagged with:

  • scenario โ€“ the name of the simulation

๐ŸŒ Exporting with OpenTelemetry

You can integrate OpenTelemetry to export traces, metrics, and logs from Simulate to the console or any OpenTelemetry-compatible backend (like Jaeger, Prometheus, or OTLP).

Example: Export to Console

using OpenTelemetry;
using OpenTelemetry.Trace;
using OpenTelemetry.Metrics;
using OpenTelemetry.Logs;
using Microsoft.Extensions.Logging;

var serviceName = "Simulate";
var serviceVersion = "0.0.5";

// Configure logging
using var loggerFactory = LoggerFactory.Create(builder =>
{
    builder.AddOpenTelemetry(options =>
    {
        options.IncludeScopes = true;
        options.ParseStateValues = true;
        options.AddConsoleExporter();
    });
});

// Configure tracing
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
    .AddSource(serviceName)
    .SetResourceBuilder(ResourceBuilder.CreateDefault()
        .AddService(serviceName: serviceName, serviceVersion: serviceVersion))
    .AddConsoleExporter()
    .Build();

// Configure metrics
using var meterProvider = Sdk.CreateMeterProviderBuilder()
    .AddMeter(serviceName)
    .SetResourceBuilder(ResourceBuilder.CreateDefault()
        .AddService(serviceName: serviceName, serviceVersion: serviceVersion))
    .AddConsoleExporter()
    .Build();

// Configure logging
using var loggerFactory = LoggerFactory.Create(builder =>
                            {
                                builder.AddOpenTelemetry(logging =>
                                {
                                    logging.AddOtlpExporter(options => options.Endpoint = new Uri("http://your-otlp-endpoint:4317"));
                                }
                            });

Place this configuration before running your simulation:

await new Simulation("example", async _ =>
{
    await Task.Delay(100);
    return new Result(true);
}, loggerFactory)
.RunFor(TimeSpan.FromSeconds(3), copies: 5, rate: 2)
.Run();

๐Ÿงช Testing

Use MeterListener, ActivityListener, and structured log capturing to test your simulation results.

[TestMethod]
public async Task Should_Record_Metrics()
{
    var metrics = new List<string>();
    using var listener = new MeterListener();

    listener.InstrumentPublished = (inst, _) => listener.EnableMeasurementEvents(inst);
    listener.SetMeasurementEventCallback<long>((inst, measurement, tags, _) =>
    {
        metrics.Add($"{inst.Name}: {measurement}");
    });
    listener.Start();

    var results = await new Simulation("test", async () =>
    {
        await Task.Delay(10);
        return new Result(true);
    })
    .RunFor(TimeSpan.FromSeconds(1), copies: 1)
    .Run();

    Assert.IsTrue(results.Successes > 0);
    Assert.IsTrue(metrics.Count > 0);
}

๐Ÿ“„ License

This project is licensed under the MIT License. See LICENSE for details.

๐Ÿค Contributing

Contributions, suggestions, and issues are welcome. Please open a PR or file an issue in GitHub.

๐Ÿ“ฌ Contact

Questions? Reach out on GitHub or submit an issue.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.5 411 8/26/2025
0.0.4 142 8/22/2025
0.0.3 82 8/22/2025
0.0.2 78 8/22/2025
0.0.1 819 6/5/2025