datadog-ux-utils Documentation - v1.0.0
    Preparing search index...

    Function startFlow

    • Starts a flow timer for a named user or app flow (e.g., "checkout", "search_to_results"). Returns an object with end() and fail() methods to mark completion or failure.

      Parameters

      • name: string

        A unique name for this flow type (e.g., "checkout", "search_to_results")

      • ctx: Record<string, unknown> = {}

        Optional initial context to include in all events for this flow

      Returns {
          end(extra?: Record<string, unknown>): void;
          fail(err: unknown, extra?: Record<string, unknown>): void;
      }

      An object with end() and fail() methods

      • end: function
        • Ends the flow successfully and sends a flow_end action.

          Parameters

          • Optionalextra: Record<string, unknown>

            Optional extra context to include in the event

          Returns void

          flow.end({ orderId });
          
      • fail: function
        • Marks the flow as failed and sends a flow_fail action and error telemetry.

          Parameters

          • err: unknown

            The error or reason for failure

          • Optionalextra: Record<string, unknown>

            Optional extra context to include in the event

          Returns void

          flow.fail(new Error("Payment failed"), { step: "payment" });
          
      const flow = startFlow("checkout", { userId });
      // ... user completes checkout
      flow.end({ orderId });
      // or, on error:
      flow.fail(new Error("Payment failed"), { step: "payment" });