Skip to main content

NetMediate Diagnostics

Built-in OpenTelemetry traces and metrics

NetMediate emits diagnostics primitives for every mediator operation via the standard .NET ActivitySource and Meter APIs.

ActivitySource

Name: NetMediate (NetMediateDiagnostics.ActivitySourceName)

An Activity is started for each operation:

OperationActivity nameTags
IMediator.SendNetMediate.Sendnetmediate.operation, netmediate.message_type
IMediator.RequestNetMediate.Requestnetmediate.operation, netmediate.message_type
IMediator.NotifyNetMediate.Notifynetmediate.operation, netmediate.message_type
IMediator.RequestStreamNetMediate.RequestStreamnetmediate.operation, netmediate.message_type

Activities are only started when the ActivitySource has at least one listener — there is no overhead when tracing is not configured.

Meter

Name: NetMediate (NetMediateDiagnostics.MeterName)

Counter nameConstantIncremented by
netmediate.send.countNetMediateDiagnostics.SendCountMetricNameIMediator.Send
netmediate.request.countNetMediateDiagnostics.RequestCountMetricNameIMediator.Request
netmediate.notify.countNetMediateDiagnostics.NotifyCountMetricNameIMediator.Notify
netmediate.dispatch.countNetMediateDiagnostics.DispatchCountMetricNameinternal handler dispatch
netmediate.stream.countNetMediateDiagnostics.StreamCountMetricNameIMediator.RequestStream

All counters carry a message_type tag with the message CLR type name. Counters are only recorded when the Counter is enabled — there is no overhead when metrics are not configured.

Quick integration example

builder.Services.AddOpenTelemetry()
.WithTracing(t => t.AddSource(NetMediateDiagnostics.ActivitySourceName))
.WithMetrics(m => m.AddMeter(NetMediateDiagnostics.MeterName));

For DataDog, use the dedicated package instead:

builder.Services.AddNetMediateDataDogOpenTelemetry(options =>
{
options.ServiceName = "my-service";
options.OtlpEndpoint = new Uri("http://localhost:4318");
});

See DataDog Integration for full details.

Performance comparison (main vs current branch)

Measurements were captured with the same load scenarios used in tests, using 5 runs per branch and reporting the median throughput:

  • command: 20,000 operations
  • request_parallel: 10,000 operations

Environment used for these measurements:

  • CPU/vCPU: AMD EPYC 7763 with 4 vCPU
  • Memory: 15 GiB RAM
Scenarioorigin/main median throughput (ops/s)Current branch median throughput (ops/s)Delta
command172,650.29179,843.50+4.17%
request_parallel280,944.65118,619.88-57.78%

Notes:

  • command throughput improved slightly with the current branch in this environment.
  • request throughput is lower because this branch adds extra per-request work in the hot path (behavior-chain resolution + diagnostics counters/tags + activity lifecycle checks).
  • benchmark results are sensitive to runtime environment noise. Re-run multiple times for stable medians before release decisions.

See Also