Table of Contents

Class ContextFlowTracker

Namespace
Excalibur.Dispatch.Observability.Context
Assembly
Excalibur.Dispatch.Observability.dll

Main tracking component that records context state at each pipeline stage, detects changes/losses in context fields, correlates context across service boundaries, and tracks context lineage throughout the message processing lifecycle.

public sealed class ContextFlowTracker : IContextFlowTracker, IDisposable, IAsyncDisposable
Inheritance
ContextFlowTracker
Implements
Inherited Members
Extension Methods

Constructors

ContextFlowTracker(ILogger<ContextFlowTracker>, IOptions<ContextObservabilityOptions>, IContextFlowMetrics)

Initializes a new instance of the ContextFlowTracker class.

public ContextFlowTracker(ILogger<ContextFlowTracker> logger, IOptions<ContextObservabilityOptions> options, IContextFlowMetrics metrics)

Parameters

logger ILogger<ContextFlowTracker>

Logger for diagnostic output.

options IOptions<ContextObservabilityOptions>

Configuration options for context observability.

metrics IContextFlowMetrics

Metrics collector for context flow tracking.

Methods

CorrelateAcrossBoundary(IMessageContext, string)

Correlates context across service boundaries for distributed tracing.

public void CorrelateAcrossBoundary(IMessageContext context, string serviceBoundary)

Parameters

context IMessageContext

The message context.

serviceBoundary string

The service boundary identifier.

DetectChanges(IMessageContext, string, string)

Detects changes or losses in context fields between pipeline stages.

public IEnumerable<ContextChange> DetectChanges(IMessageContext context, string fromStage, string toStage)

Parameters

context IMessageContext

The current message context.

fromStage string

The previous pipeline stage.

toStage string

The current pipeline stage.

Returns

IEnumerable<ContextChange>

A collection of detected changes.

Dispose()

Releases all resources used by the ContextFlowTracker.

public void Dispose()

DisposeAsync()

Asynchronously releases resources, ensuring the cleanup timer callback has completed.

public ValueTask DisposeAsync()

Returns

ValueTask

GetContextLineage(string)

Gets the complete context lineage for a specific correlation ID.

public ContextLineage? GetContextLineage(string correlationId)

Parameters

correlationId string

The correlation ID.

Returns

ContextLineage

The context lineage or null if not found.

GetMessageSnapshots(string)

Gets all snapshots for a specific message.

public IEnumerable<ContextSnapshot> GetMessageSnapshots(string messageId)

Parameters

messageId string

The message ID.

Returns

IEnumerable<ContextSnapshot>

Collection of snapshots for the message.

RecordContextState(IMessageContext, string, IReadOnlyDictionary<string, object>?)

Records the current state of a message context at a specific pipeline stage.

public void RecordContextState(IMessageContext context, string stage, IReadOnlyDictionary<string, object>? metadata = null)

Parameters

context IMessageContext

The message context to track.

stage string

The current pipeline stage.

metadata IReadOnlyDictionary<string, object>

Additional metadata about the tracking point.

ValidateContextIntegrity(IMessageContext)

Validates that the context contains all required fields.

public bool ValidateContextIntegrity(IMessageContext context)

Parameters

context IMessageContext

The message context to validate.

Returns

bool

True if context is valid; otherwise false.