Muonroi.Observability
2.0.2
dotnet add package Muonroi.Observability --version 2.0.2
NuGet\Install-Package Muonroi.Observability -Version 2.0.2
<PackageReference Include="Muonroi.Observability" Version="2.0.2" />
<PackageVersion Include="Muonroi.Observability" Version="2.0.2" />
<PackageReference Include="Muonroi.Observability" />
paket add Muonroi.Observability --version 2.0.2
#r "nuget: Muonroi.Observability, 2.0.2"
#:package Muonroi.Observability@2.0.2
#addin nuget:?package=Muonroi.Observability&version=2.0.2
#tool nuget:?package=Muonroi.Observability&version=2.0.2
Muonroi.Observability
OpenTelemetry and Serilog integration for Muonroi: unified metrics, distributed tracing, and structured logging.
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:
TenantIdEnricherautomatically appendsTenantIdto Serilog logs, while OTel processors append it to tracing spans. - Log Sanitization: Includes
ILogSanitizerandLogSanitizerto automatically mask or redact sensitive information (e.g., PII, passwords) before logs are flushed. - Custom Metrics: Exposes
MuonroiMetricsfor 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 | Versions 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. |
-
net8.0
- Muonroi.Core.Abstractions (>= 2.0.2)
- Muonroi.Governance.Abstractions (>= 2.0.2)
- Muonroi.Tenancy.Abstractions (>= 2.0.2)
- OpenTelemetry.Exporter.OpenTelemetryProtocol (>= 1.15.3)
- OpenTelemetry.Extensions.Hosting (>= 1.9.0)
- OpenTelemetry.Instrumentation.AspNetCore (>= 1.9.0)
- OpenTelemetry.Instrumentation.GrpcNetClient (>= 1.9.0-beta.1)
- OpenTelemetry.Instrumentation.Http (>= 1.9.0)
- OpenTelemetry.Instrumentation.Runtime (>= 1.9.0)
- Serilog.Enrichers.Span (>= 3.1.0)
- Serilog.Exceptions (>= 8.4.0)
- Serilog.Extensions.Hosting (>= 8.0.0)
- Serilog.Settings.Configuration (>= 8.0.4)
- Serilog.Sinks.Async (>= 2.1.0)
- Serilog.Sinks.Console (>= 6.0.0)
- Serilog.Sinks.File (>= 6.0.0)
- Serilog.Sinks.OpenTelemetry (>= 1.2.0)
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.