April 10th 2024

New

Multistep Checks GA

We are excited to announce that Multistep checks are now in General Availability.

Increase reliability and confidence in your API user flows by chaining together multiple requests in a single check.

What is a Multistep Check?

Like Checkly’s Browser checks, a Multistep check is a fully programmable Playwright test script at its core. It uses Playwright's API testing framework to mimic real user journeys and actions. The flexible nature of the check allows you to change, delete, or add new data in between requests, simulating any user action.

Unlike traditional multistep monitoring, you are not limited to a form builder; you can create a check that monitors exactly what you need.

Of course, Multistep checks support Checkly’s monitoring-as-code workflow, not limiting you to working in our in-app editor. Work from your preferred IDE, and use our CLI to automatically update your monitors as part of your CI/CD process.

Creating your first Multistep check

To get started, simply log in to Checkly and click the ‘+’ button in the left-hand sidebar. Select ‘Multistep check’ from the options and either choose a template that fits your use case, or start from scratch.

Multistep checks use Playwrights test.step method to build the check result tree. We recommend only using a single request per step in your test, and use descriptive labels for each step to make debugging and analyzing failed check runs easier. Here’s a short example.

import { test, expect } from '@playwright/test'

const baseUrl = 'https://api.myproduct.com/v1'

test('My test', async ({request}) => {
    await test.step('First step', async () => {
        const health = await request.get(`${baseUrl}/health`)
        expect(health).toBeOK()
    });

    await test.step('Second step', async () => {
        const response = await request.post(`${baseUrl}/health`)
        // Assertions for the second step
        ...
    })
})

You can test-run the script directly from the check editor to confirm it is working as intended. The left-hand sidebar contains the check results from your ad-hoc runs for easy debugging.

Multistep checks are supported on the Checkly runtime 2023.09 or later.

Degraded state and soft assertions

If you want to monitor your API for non-critical errors or performance degradations you can use the degraded check state. This allows you to signal that parts of a multistep check performed slower than expected, or that it triggered assertions that are of lower criticality.

To trigger a degraded state multistep checks use a helper library, @checkly/playwright-helpers, which is included in runtime 2023.09 and later. The helper library contains two methods, markCheckAsDegraded and getAPIResponseTime.

Here is an example of how to use the degraded state in a check together with soft assertions from Playwright to signal that something is not performing as expected, without interrupting the execution of the check.

import { test, expect } from '@playwright/test'
import { getAPIResponseTime, markCheckAsDegraded } from "@checkly/playwright-helpers"

const baseUrl = 'https://api.myproduct.com/v1'

test('My test', async ({request}) => {
    await test.step('First step', async () => {
        const health = await request.get(`${baseUrl}/health`)
        expect(health).toBeOK()
        
        //Check if the request status is degraded
        expect.soft(getAPIResponseTime(health), 'GET /health is too  slow').toBeLessThanOrEqual(200)
    });

  // Trigger degraded state if check failed due to soft assertion
  if (test.info().errors.length) {
    markCheckAsDegraded('Check degraded due to soft assertion failure.')
  }
})

@checkly/playwright-helpers is also available for use in browser checks.

Multistep checks and monitoring as code

Multistep checks are fully supported in the Checkly monitoring as code workflow. You can use either the Checkly CLI or our Terraform provider. Here is an example of how to use the MultistepCheck construct.

import { MultiStepCheck } from 'checkly/constructs'

new MultiStepCheck('multistep-check-1', {
  name: 'Multistep Check #1',
  runtimeId: '2024.02',
  frequency: Frequency.EVERY_10M,
  locations: ['us-east-1', 'eu-west-1'],
  code: {
    entrypoint: path.join(__dirname, 'home.spec.ts')
  },
})

Availability and price

Multistep checks are available on all current Checkly price plans. Each request in a multistep check counts as a single API check run for billing purposes.

Additional resources

If you have questions or feedback, join our Slack community and share your thoughts with Checkly users from across the globe.

Happy monitoring!

Type @ to mention posts