Array of registered activity interceptors that will wrap individual proxied activity calls in the order they were registered (first registered = outermost wrapper).
Array of registered workflow interceptors that will wrap workflow execution in the order they were registered (first registered = outermost wrapper).
Execute the activity interceptor chain around an activity invocation. Uses the same onion/reduceRight pattern as executeChain.
Metadata about the activity (name, args, options)
The workflow context Map
The core activity function (registers with interruptionRegistry, sleeps, throws)
The result of the activity (from replay or after future execution)
Execute the interceptor chain around the workflow function. The chain is built in an onion pattern where each interceptor wraps the next one, with the workflow function at the center.
The workflow context map
The workflow function to execute
The result of the workflow execution
Register a new workflow interceptor that will wrap workflow execution. Interceptors are executed in the order they are registered, with the first registered interceptor being the outermost wrapper.
The interceptor to register
Register a new activity interceptor that will wrap individual proxied activity calls. Interceptors are executed in the order they are registered, with the first registered being the outermost wrapper.
The activity interceptor to register
Service for managing workflow interceptors that wrap workflow execution in an onion-like pattern. Each interceptor can perform actions before and after workflow execution, add cross-cutting concerns, and handle errors.
Basic Interceptor Pattern
Example
Durable Interceptors with Durable Functions
Interceptors run within the workflow's async local storage context, which means they can use Durable functions like
sleepFor,entity,proxyActivities, etc. These interceptors participate in the HotMesh interruption/replay pattern.Example
Execution Pattern with Interruptions
When interceptors use Durable functions, the workflow will execute multiple times due to the interruption/replay pattern:
sleepFor→ throwsDurableSleepError→ workflow pausesDurableProxyError→ workflow pausesDurableSleepError→ workflow pausesThis pattern ensures deterministic, durable execution across all interceptors and workflow code.
Example
Activity Interceptors
Activity interceptors wrap individual proxied activity calls, supporting both before and after phases. The before phase receives the activity input (and can modify
activityCtx.args). The after phase receives the activity output as the return value ofnext().This enables patterns like publishing activity results to an external system (e.g., SNS, audit log) without modifying the workflow itself.
Important: The after-phase proxy activity calls go through the same interceptor chain. Guard against recursion by checking
activityCtx.activityNameto skip the interceptor's own calls.Example
Activity Interceptor Replay Pattern
Activity interceptors participate in the interruption/replay cycle:
next()registers the activity interruption and throwsDurableProxyError→ workflow pausesnext()returns the stored activity result → after-phase runs → after-phase proxy call (e.g.,publishToSNS) registers its own interruption → workflow pauses