getStepMetadata
Returns metadata available in the current step function.
You may want to use this function when you need to:
- Track retry attempts in error handling
- Access timing information of a step and execution metadata
This function can only be called inside a step function.
import { getStepMetadata } from "workflow"
async function testWorkflow() {
"use workflow"
await logStepId()
}
async function logStepId() {
"use step"
const ctx = getStepMetadata()
console.log(ctx.stepId) // Grab the current step ID
}API Signature
Parameters
This function does not accept any parameters.
Returns
| Name | Type | Description |
|---|---|---|
stepId | string | Unique identifier for the currently executing step. Useful to use as part of an idempotency key for critical operations that must only be executed once (such as charging a customer). |
stepStartedAt | Date | Timestamp when the current step started. |
attempt | number | The number of times the current step has been executed. This will increase with each retry. |