Class MediatorTraceProviderBuilderExtensions
Extension methods for configuring OpenTelemetry tracing for the Trellis mediator pipeline.
public static class MediatorTraceProviderBuilderExtensions
- Inheritance
-
MediatorTraceProviderBuilderExtensions
- Inherited Members
Methods
AddTrellisMediatorInstrumentation(TracerProviderBuilder)
Adds Trellis mediator pipeline instrumentation to the OpenTelemetry tracer provider, so the per-command and per-query span opened by TracingBehavior<TMessage, TResponse> is collected.
public static TracerProviderBuilder AddTrellisMediatorInstrumentation(this TracerProviderBuilder builder)
Parameters
builderTracerProviderBuilderThe OpenTelemetry.Trace.TracerProviderBuilder to configure.
Returns
- TracerProviderBuilder
The same OpenTelemetry.Trace.TracerProviderBuilder instance for method chaining.
Examples
services.AddOpenTelemetry()
.WithTracing(tracing => tracing
.AddAspNetCoreInstrumentation()
.AddTrellisMediatorInstrumentation()
.AddOtlpExporter());
Remarks
AddTrellisBehaviors() registers TracingBehavior<TMessage, TResponse>,
so every command and query already *calls* StartActivity. That call only produces a
live activity if a listener is subscribed to the source, so without this registration
StartActivity returns null and the handler span is never collected.
Why this matters more than a missing span. The absence is indistinguishable
from success: a service with no handler spans looks exactly like a service in which nothing
failed. The failure tags this span carries — error.code and error.type, the
same values the HTTP response body reports — are the ones an operator reaches for when
asking which rule rejected a request, so the configuration gap is discovered during an
incident rather than before one.
The registered source is ActivitySourceName
("Trellis.Mediator"). Consumers may equivalently call AddSource("Trellis.Mediator");
this helper exists so the name does not have to be repeated as a string literal, matching
AddTrellisResultsInstrumentation() in Trellis.Core and
AddTrellisPrimitivesInstrumentation() in Trellis.Primitives. The method is named for
the Trellis pipeline specifically because it instruments Trellis behaviors rather than the
underlying Mediator library.
This is the pipeline-behavior altitude that the Trellis.Core tracing guidance recommends for
high-throughput services, in preference to per-Result-operator spans: one span per
request carrying the business message name and the failure code.