Initialize your project
Run the following command in the root of your backend repository, replacing The
fp_project_xxx with your actual project key:init command does four things:- Writes
FAILPATH_PROJECT_KEYto a.envfile - Adds
.envto your.gitignore - Creates
.failpath/AGENTS.md - Pulls your project’s current dashboard graph into
.failpath/flows.json
Inspect .failpath/flows.json
Open Keep this file open as a reference while you instrument your function.
.failpath/flows.json. You will see one or more flow objects. Two fields are important when writing SDK code:flow.slug— pass this string as the first argument torun(). It identifies which flow a run belongs to.node.sdkStepKey— pass this string as the first argument tostep(). It maps a recorded event to a specific node on your dashboard graph.
Create the client
Create the Failpath client once at the module level and export it as a singleton. Importing the same instance across your codebase ensures that configuration — like The
defaultMetadata — is applied consistently everywhere.projectKey is read from the environment variable written by npx failpath init. In local development your .env file supplies it automatically.Wrap your function steps
Import your client and use Each
run() to start a run, then wrap each business step with step(). Pass the flow.slug to run() and the matching sdkStepKey to each step() call. Reuse the same runId for every step that belongs to the same request.step() call sends a running event before the wrapped operation executes, then sends success or error when it finishes.