Table of Contents

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

tracker IContextFlowTracker

Context flow tracker for recording context state.

metrics IContextFlowMetrics

Metrics collector for context flow.

traceEnricher IContextTraceEnricher

Trace enricher for adding context to spans.

options IOptions<ContextObservabilityOptions>

Configuration options.

logger ILogger<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

DispatchMiddlewareStage?

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

message IDispatchMessage

The message being processed.

context IMessageContext

The message context being processed.

nextDelegate DispatchRequestDelegate

The next middleware in the pipeline.

cancellationToken CancellationToken

Cancellation token for the operation.

Returns

ValueTask<IMessageResult>

The result of processing the message.