Snowberry.Mediator.OpenTelemetry.Shared 3.0.0

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

Snowberry.Mediator.OpenTelemetry.Shared

Container-agnostic OpenTelemetry instrumentation for Snowberry.Mediator. InstrumentedMediator decorates IMediator and emits an Activity plus count and duration metrics for every SendAsync, CreateStreamAsync and PublishAsync, with opt-in spans per pipeline behavior and per notification handler. It targets net11.0, net10.0 and netstandard2.0 and depends on OpenTelemetry.Api.

Applications normally reference the integration for their container, which brings this package in:

Container Package
Microsoft.Extensions.DependencyInjection Snowberry.Mediator.Extensions.OpenTelemetry
Snowberry.DependencyInjection Snowberry.Mediator.OpenTelemetry

Table of Contents

Installation

dotnet add package Snowberry.Mediator.OpenTelemetry.Shared

Exporters and the SDK (OpenTelemetry, OpenTelemetry.Exporter.*, OpenTelemetry.Extensions.Hosting) are not included; add the ones your app uses.

Quick Start

Decorate the mediator through your container's integration, then subscribe the OpenTelemetry SDK to the mediator sources with the builder extensions from this package:

using OpenTelemetry;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
using Snowberry.Mediator.OpenTelemetry;   // AddSnowberryMediatorInstrumentation

using var tracerProvider = Sdk.CreateTracerProviderBuilder()
    .AddSnowberryMediatorInstrumentation()   // Snowberry.Mediator + .Pipeline + .Notification sources
    .AddConsoleExporter()                    // OpenTelemetry.Exporter.Console
    .Build();

using var meterProvider = Sdk.CreateMeterProviderBuilder()
    .AddSnowberryMediatorInstrumentation()   // Snowberry.Mediator meter
    .AddConsoleExporter()
    .Build();

Options

MediatorTelemetryOptions (namespace Snowberry.Mediator.OpenTelemetry):

Property Type Default Purpose
EnableTracing bool true Emit the dispatch Activity.
EnableMetrics bool true Record the count and duration instruments.
EnablePipelineBehaviorSpans bool false Emit one span per pipeline behavior (process-wide, see Per-Step Spans).
EnableNotificationHandlerSpans bool false Emit one span per notification handler (process-wide).
SourceName string "Snowberry.Mediator" Name of the dispatch ActivitySource and Meter.
Filter Func<object, bool>? null Return false to skip instrumentation for a request or notification.
EnrichWithRequest Action<Activity, object>? null Add tags from the request (Send, Stream).
EnrichWithResponse Action<Activity, object, object>? null Add tags from the response (Send only).
EnrichWithNotification Action<Activity, object>? null Add tags from the notification (Publish).
EnrichWithException Action<Activity, object, Exception>? null Add tags or events for a failed dispatch.

The options are read when the decorator is constructed.

How It Works

caller -> InstrumentedMediator ----------------------------> inner IMediator
             |  no tracer listening and no meter listener:    (forwarded as-is)
             |  Filter(message) == false:                     (forwarded as-is)
             |
             +-> start Activity "Mediator.Send {RequestType}"
             +-> inner.SendAsync(...)
             +-> status Ok / Error, count + duration metrics, stop Activity

The instrumented path is taken when tracing is enabled and the ActivitySource has a listener, or when metrics are enabled and an instrument is being listened to. Otherwise the call is forwarded to the inner mediator directly.

Emitted Telemetry

Activities

Source Activity name Tags
Snowberry.Mediator Mediator.Send {RequestType} snowberry.mediator.request.type, snowberry.mediator.response.type, snowberry.mediator.operation = send
Snowberry.Mediator Mediator.Stream {RequestType} snowberry.mediator.request.type, snowberry.mediator.response.type, snowberry.mediator.operation = stream
Snowberry.Mediator Mediator.Publish {NotificationType} snowberry.mediator.notification.type, snowberry.mediator.operation = publish
Snowberry.Mediator.Pipeline (opt-in) Mediator.Behavior {BehaviorType} snowberry.mediator.behavior.type, snowberry.mediator.request.type
Snowberry.Mediator.Notification (opt-in) Mediator.Handler {HandlerType} snowberry.mediator.handler.type, snowberry.mediator.notification.type
  • All activities use ActivityKind.Internal. The status is Ok on success and Error (with the exception message) on failure; no exception event is recorded, so add one in EnrichWithException if you need it.
  • Type names are Type.FullName (for example MyApp.Orders.PlaceOrder), so types that share a simple name across namespaces are not conflated. For closed generic types, such as open-generic behaviors closed at runtime, the full name includes assembly-qualified type arguments.
  • Stream activities start on the first MoveNextAsync and cover the whole enumeration, including time spent in the consumer.

Metrics

Meter name: SourceName (default Snowberry.Mediator).

Instrument Type Unit Tags
snowberry.mediator.send.count Counter<long> type, status
snowberry.mediator.send.duration Histogram<double> ms type, status
snowberry.mediator.stream.count Counter<long> type, status
snowberry.mediator.stream.duration Histogram<double> ms type, status
snowberry.mediator.publish.count Counter<long> type, status
snowberry.mediator.publish.duration Histogram<double> ms type, status

status is success or failure. A stream the consumer stops enumerating early counts as failure.

Instrumentation scope

Every ActivitySource and the Meter carry the package version as their version, exported as the OpenTelemetry instrumentation scope version. It is available as MediatorTelemetryConventions.c_InstrumentationVersion. All names and tag keys are public constants on MediatorTelemetryConventions (ActivityNames, Tags, Operations, Status, Instruments, HookNames).

Per-Step Spans

options.EnablePipelineBehaviorSpans = true;     // Mediator.Behavior spans, request and stream pipelines
options.EnableNotificationHandlerSpans = true;  // Mediator.Handler spans
  • The flags are process-wide and cannot be turned off again: enabling them calls MediatorDiagnostics.EnablePipelineSpans() / EnableNotificationSpans() in the core package when the decorator is registered. You can call those methods directly to get per-step spans without the decorator.
  • Per-step spans come from the fixed Snowberry.Mediator.Pipeline and Snowberry.Mediator.Notification sources and ignore EnableTracing and Filter.
  • AddSnowberryMediatorInstrumentation() on the tracer builder subscribes both sources.

Enrichment and Filtering

  • Enrichment callbacks never break a dispatch. An exception thrown from an EnrichWith* callback is caught and recorded as an Activity event named snowberry.mediator.enrichment.failed with the tags exception.type, exception.message and snowberry.mediator.hook.name.
  • Callbacks run only when an Activity exists, so not in metrics-only mode and not when the span is sampled out.
  • EnrichWithException runs for failed SendAsync, PublishAsync and CreateStreamAsync calls, including a stream whose inner mediator fails before enumeration starts (for example HandlerNotFoundException). It does not run when a consumer merely stops enumerating early; the span is still marked Error.
  • Filter is not guarded. It runs before any Activity exists, so an exception from Filter propagates out of the dispatch call. Keep it total (non-throwing).

Other Containers

The building blocks are public, so any container can be wired by hand:

var options = new MediatorTelemetryOptions();
var instrumentation = new MediatorInstrumentation(options);      // owns ActivitySource, Meter, instruments; IDisposable
IMediator instrumented = new InstrumentedMediator(innerMediator, instrumentation, options);

MediatorDiagnostics.EnablePipelineSpans();                      // per-step spans are switched on separately

Register MediatorInstrumentation as a singleton and dispose it with the container. The EnablePipelineBehaviorSpans / EnableNotificationHandlerSpans options only take effect through the DI integrations; call MediatorDiagnostics directly when wiring by hand.

Pitfalls

  • A custom SourceName must be passed to the builders. Use AddSnowberryMediatorInstrumentation(sourceName) on the tracer builder and AddSnowberryMediatorInstrumentation(meterName) on the meter builder; the parameterless overloads subscribe to Snowberry.Mediator and would miss everything.
  • A meter listener alone activates the instrumented path. Subscribing a MeterProvider makes every dispatch go through the decorator even without tracing; set EnableMetrics = false if you only want spans.
  • Per-step span flags are one-way. Once enabled they stay on for the process, including other mediator instances.
  • Keep Filter non-throwing. Its exceptions reach the caller.
Package Purpose
Snowberry.Mediator The mediator implementation and MediatorDiagnostics.
Snowberry.Mediator.Extensions.OpenTelemetry Decorator wiring for Microsoft.Extensions.DependencyInjection.
Snowberry.Mediator.OpenTelemetry Decorator wiring for Snowberry.DependencyInjection.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 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.  net11.0 is compatible. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Snowberry.Mediator.OpenTelemetry.Shared:

Package Downloads
Snowberry.Mediator.Extensions.OpenTelemetry

Microsoft.Extensions.DependencyInjection integration for Snowberry.Mediator OpenTelemetry.

Snowberry.Mediator.OpenTelemetry

Snowberry.DependencyInjection integration for Snowberry.Mediator OpenTelemetry.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 204 11/12/2026
2.0.0 3,411 6/1/2026