Class KevlarContext
- Namespace
- Kevlar
- Assembly
- Kevlar.dll
Ambient state for a single execution flowing through a shield pipeline. Contexts are created and pooled by Kevlar automatically; user code observes them in strategy callbacks or context-aware execution delegates and never needs to construct or return them. A context is valid only during the current callback or delegate invocation and must never be retained.
public sealed class KevlarContext
- Inheritance
-
KevlarContext
- Inherited Members
Remarks
Debug builds of Kevlar enforce that contract: a context that has gone back to the pool throws InvalidOperationException from every public member until it is handed out again. Release builds carry no such check, so a retained context there silently observes another execution's state.
Properties
CancellationToken
The cancellation token for the current scope. Strategies such as timeouts replace this token for the layers beneath them, which is why executed delegates must use the token they are handed rather than a captured one.
public CancellationToken CancellationToken { get; }
Property Value
IsSynchronous
true when the execution was started through a synchronous Execute call.
public bool IsSynchronous { get; }
Property Value
Properties
Custom properties carried through the execution. The bag is pooled with this context and must not be retained beyond the current callback or delegate invocation.
public KevlarProperties Properties { get; }
Property Value
ShieldName
The name of the executing shield, if one was assigned via WithName.
public string? ShieldName { get; }
Property Value
StrategyIndex
The zero-based position of the strategy currently executing, or -1 outside a
strategy. Nested strategies temporarily replace this value and restore it on return.
public int StrategyIndex { get; }
Property Value
TimeProvider
The time provider used for delays, timeouts and time-window calculations.
public TimeProvider TimeProvider { get; }
Property Value
Methods
RecordEvent(string, KevlarTelemetrySeverity, Exception?, int?, string?)
Records a custom low-cardinality strategy event.
public void RecordEvent(string eventName, KevlarTelemetrySeverity severity = KevlarTelemetrySeverity.Information, Exception? exception = null, int? attemptNumber = null, string? strategyName = null)
Parameters
eventNamestringA stable event name from a bounded vocabulary.
severityKevlarTelemetrySeverityThe event severity.
exceptionExceptionAn associated exception, if any. Exception messages are never metric tags.
attemptNumberint?The zero-based attempt number, or null to use the active retry attempt.
strategyNamestringA stable low-cardinality custom strategy name.