Execution Hooks
Attach custom behavior to workflow execution without changing logic. Add logging, metrics, or tracing at key lifecycle moments.
Overview
Hooks let you observe and extend workflow execution. They're perfect for:
- •Logging task starts, completions, and failures
- •Collecting metrics on execution time and costs
- •Distributed tracing for debugging
- •Custom error handling and recovery
Using the Default Hook
Mosaic provides a default hook that logs execution events:
Creating Custom Hooks
Create your own hooks to add custom behavior:
Combining Multiple Hooks
Use ClusterHook to combine multiple hooks:
Tip
Hook Lifecycle Events
onWorkflowStart
Called when a workflow begins execution. Useful for initializing resources.
onTaskStart
Called before each task executes. Track task starts, set up context.
onTaskComplete
Called when a task completes successfully. Record metrics, log results.
onTaskError
Called when a task fails. Handle errors, trigger alerts, implement retry logic.
onWorkflowComplete
Called when the entire workflow finishes. Clean up resources, summarize results.