Class ContextObservabilityMiddleware
- Namespace
- Excalibur.Dispatch.Observability.Context
- Assembly
- Excalibur.Dispatch.Observability.dll
Middleware that instruments each pipeline stage with context observability, adding trace spans for context operations, recording context snapshots, and detecting context mutations throughout the message processing pipeline.
public sealed class ContextObservabilityMiddleware : IDispatchMiddleware, IDisposable, IAsyncDisposable
- Inheritance
-
ContextObservabilityMiddleware
- Implements
- Inherited Members
- Extension Methods
Remarks
Initializes a new instance of the ContextObservabilityMiddleware class.
Constructors
ContextObservabilityMiddleware(IContextFlowTracker, IContextFlowMetrics, IContextTraceEnricher, IOptions<ContextObservabilityOptions>, ILogger<ContextObservabilityMiddleware>)
Middleware that instruments each pipeline stage with context observability, adding trace spans for context operations, recording context snapshots, and detecting context mutations throughout the message processing pipeline.
public ContextObservabilityMiddleware(IContextFlowTracker tracker, IContextFlowMetrics metrics, IContextTraceEnricher traceEnricher, IOptions<ContextObservabilityOptions> options, ILogger<ContextObservabilityMiddleware> logger)
Parameters
trackerIContextFlowTrackerContext flow tracker for recording context state.
metricsIContextFlowMetricsMetrics collector for context flow.
traceEnricherIContextTraceEnricherTrace enricher for adding context to spans.
optionsIOptions<ContextObservabilityOptions>Configuration options.
loggerILogger<ContextObservabilityMiddleware>Logger for diagnostic output.
Remarks
Initializes a new instance of the ContextObservabilityMiddleware class.
Properties
Stage
Gets the stage in the dispatch pipeline where this middleware executes.
public DispatchMiddlewareStage? Stage { get; }
Property Value
Methods
Dispose()
Releases all resources used by the ContextObservabilityMiddleware.
public void Dispose()
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.
InvokeAsync(IDispatchMessage, IMessageContext, DispatchRequestDelegate, CancellationToken)
Invokes the middleware to track context flow through the pipeline.
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "Context observability captures diagnostic snapshots and handles trimmed data defensively.")]
[UnconditionalSuppressMessage("Aot", "IL3050:Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.", Justification = "Context observability uses JSON serialization for diagnostics.")]
public ValueTask<IMessageResult> InvokeAsync(IDispatchMessage message, IMessageContext context, DispatchRequestDelegate nextDelegate, CancellationToken cancellationToken)
Parameters
messageIDispatchMessageThe message being processed.
contextIMessageContextThe message context being processed.
nextDelegateDispatchRequestDelegateThe next middleware in the pipeline.
cancellationTokenCancellationTokenCancellation token for the operation.
Returns
- ValueTask<IMessageResult>
The result of processing the message.