Muonroi.Observability 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Muonroi.Observability --version 2.0.0
                    
NuGet\Install-Package Muonroi.Observability -Version 2.0.0
                    
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="Muonroi.Observability" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Muonroi.Observability" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Muonroi.Observability" />
                    
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 Muonroi.Observability --version 2.0.0
                    
#r "nuget: Muonroi.Observability, 2.0.0"
                    
#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 Muonroi.Observability@2.0.0
                    
#: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=Muonroi.Observability&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Muonroi.Observability&version=2.0.0
                    
Install as a Cake Tool

Muonroi.Observability

OpenTelemetry and Serilog integration for Muonroi: unified metrics, distributed tracing, and structured logging.

NuGet License

Overview

The Muonroi.Observability package provides a turnkey solution for instrumenting applications within the Muonroi ecosystem. It opinionates the setup of OpenTelemetry (OTel) for traces and metrics, and Serilog for structured logging, ensuring that telemetry signals are correctly correlated across distributed microservices.

A key challenge in multi-tenant systems is ensuring that telemetry data is context-aware without explicitly passing IDs through every method call. This package integrates deeply with Muonroi.Tenancy.Abstractions to automatically enrich logs, spans, and metrics with Tenant IDs, ensuring that dashboards and alerts can be segmented by tenant out of the box.

Use this package in the entry point of any API, worker, or web application to establish a robust observability baseline.

Features

  • OpenTelemetry Bootstrapping: AddMuonroiObservability() configures OTel Tracing and Metrics to export via OTLP.
  • Tenant Context Enrichment: TenantIdEnricher automatically appends TenantId to Serilog logs, while OTel processors append it to tracing spans.
  • Log Sanitization: Includes ILogSanitizer and LogSanitizer to automatically mask or redact sensitive information (e.g., PII, passwords) before logs are flushed.
  • Custom Metrics: Exposes MuonroiMetrics for recording domain-specific measurements (e.g., active tenants, rule engine evaluations, quota usage).

Installation

dotnet add package Muonroi.Observability

Quick Start

Configuring Observability in Program.cs

using Muonroi.Observability;
using Muonroi.Observability.Logging;

var builder = WebApplication.CreateBuilder(args);

// 1. Configure Serilog
builder.Host.UseMuonroiSerilog((context, loggerConfig) =>
{
    loggerConfig.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] [{TenantId}] {Message:lj}{NewLine}{Exception}");
});

// 2. Configure OpenTelemetry
builder.Services.AddMuonroiObservability(builder.Configuration);

Recording Custom Metrics

Inject MuonroiMetrics to record domain-specific counters or histograms.

using Muonroi.Observability.OpenTelemetry;

public class OrderService
{
    private readonly MuonroiMetrics _metrics;

    public OrderService(MuonroiMetrics metrics)
    {
        _metrics = metrics;
    }

    public void ProcessOrder(Order order)
    {
        // Record the metric. The tenant ID will be captured automatically by the OTel context.
        _metrics.OrderProcessedCounter.Add(1, new KeyValuePair<string, object?>("order.type", order.Type));
    }
}

Ecosystem Combinations

+ Muonroi.Tenancy.Core → Tenant-Aware Tracing

TenantIdEnricher securely tags all spans/logs/metrics with the resolved tenant.id from ISystemExecutionContextAccessor, enabling per-tenant telemetry isolation without passing context manually.

+ Muonroi.Diagnostics → Embedded Diagnostic Sessions

Log entries emitted within a diagnostic session are attached to the current trace node, creating a combined log+trace view, directly exportable via OTLP.

+ Muonroi.Messaging.MassTransit → Distributed Message Correlation

Correlates log entries to OTel trace spans via TraceId/SpanId across message bus boundaries.

Full Observability Stack

builder.Services
    .AddMuonroiObservability(config)
    .AddTenantContext(config);

Samples

License

Apache 2.0 — see LICENSE-APACHE.

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

Showing the top 3 NuGet packages that depend on Muonroi.Observability:

Package Downloads
Muonroi.Resilience

Polly-based resilience patterns for Muonroi: retry, circuit breaker, timeout, and bulkhead policies with OTel integration.

Muonroi.BuildingBlock.All

Metapackage for Muonroi Building Block - Includes all sub-packages for a complete infrastructure setup.

Muonroi.Grpc

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.2 149 8/26/2026
2.0.1 152 8/26/2026
2.0.0 169 8/14/2026