Interceptor for individual proxied activity calls within a workflow. Runs inside the workflow's async local storage context, so all Durable workflow methods (proxyActivities, sleepFor, waitFor, execChild, etc.) are available.

Activity interceptors wrap proxied activity calls in an onion pattern, supporting both before and after phases:

  • Before phase (code before await next()): Runs before the activity executes. The interceptor can inspect or modify activityCtx.args to transform the activity input before it is sent.

  • After phase (code after await next()): Runs on replay once the activity result is available. The interceptor receives the activity output as the return value of next() and can inspect or transform it.

On first execution, next() registers the activity with the interruption system and throws (the activity has not completed yet). On replay, next() returns the stored result and the after-phase code executes. This follows the same deterministic replay pattern as workflow interceptors.

const auditInterceptor: ActivityInterceptor = {
async execute(activityCtx, workflowCtx, next) {
const { auditLog } = Durable.workflow.proxyActivities<{
auditLog: (id: string, action: string) => Promise<void>;
}>({
taskQueue: 'shared-audit',
retryPolicy: { maximumAttempts: 3 },
});

await auditLog(workflowCtx.get('workflowId'), `before:${activityCtx.activityName}`);
const result = await next();
await auditLog(workflowCtx.get('workflowId'), `after:${activityCtx.activityName}`);
return result;
},
};

Durable.registerActivityInterceptor(auditInterceptor);
interface ActivityInterceptor {
    execute(activityCtx: ActivityInterceptorContext, workflowCtx: Map<string, any>, next: (() => Promise<any>)): Promise<any>;
}

Methods

Methods

  • Called around each proxied activity invocation. Code before next() runs in the before phase; code after next() runs in the after phase once the activity result is available on replay.

    Parameters

    • activityCtx: ActivityInterceptorContext

      Metadata about the activity being called (args may be modified)

    • workflowCtx: Map<string, any>

      The workflow context map (same as WorkflowInterceptor receives)

    • next: (() => Promise<any>)

      Call to proceed to the next interceptor or the core activity function

        • (): Promise<any>
        • Returns Promise<any>

    Returns Promise<any>

    The activity result (from replay or after interruption/re-execution)