Skip to content

Commit ec366ef

Browse files
committed
Restore missing env var content, plus minor fixes/updates
1 parent f82e101 commit ec366ef

6 files changed

Lines changed: 153 additions & 84 deletions

File tree

detect/synthetic-monitoring/api-checks/requests.mdx

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: 'Requests'
44
sidebarTitle: 'Requests'
55
---
66

7-
7+
import GenericRuntimeVariablesTable from '/snippets/generic-runtime-variables-table.mdx';
88

99
A full HTTP request is created by filling out the various parts of the HTTP request settings screen. Not all sections and fields
1010
are mandatory, only a name and URL are required to get going.
@@ -162,3 +162,42 @@ This list shows all content types that we scrub from the response data.
162162
|`video/x-flv`|
163163
|`video/webm`|
164164

165+
## Accessing environment variables
166+
167+
[Environment variables](/platform/variables) are exposed to your API checks using the common Handlebars/Moustache templating delimiters, i.e. `{{USER_API_KEY}}`. Note that Handlebars (double brackets) variables will be URI encoded. To avoid encoding, you can access your environment variables with triple brackets, i.e. `{{{USER_API_KEY}}}`.
168+
169+
Variables can be used in the following API checks fields:
170+
171+
- URL
172+
- Body
173+
- Header values
174+
- Query parameters values
175+
- Basic authentication username and password
176+
177+
### Using helpers and built-in variables
178+
179+
Next to your own variables, we've added some built-in ones.
180+
181+
These variables are specific to API checks:
182+
183+
| Helper | Description |
184+
|----------------------|------------ |
185+
| `{{GROUP_BASE_URL}}` | If your check belongs to a group, this resolves to the group's configured base URL. |
186+
| `{{REQUEST_URL}}` | The request URL. |
187+
| `{{$UUID}}` | Generates a random UUID/v4, i.e. 9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d. |
188+
| `{{$RANDOM_NUMBER}}` | Generates a random decimal number between 0 and 10000, i.e. 345. |
189+
| `{{moment}}` | Generates a date or time using **moment.js** and allows for formatting: <ul> <li>`{{moment "YYYY-MM-DD"}}` generates a date, i.e. 2020-08-26</li> <li>`{{moment "2 days ago" "YYYY-MM-DD"}}` generates the date two days ago: 2020-08-24</li> <li>`{{moment "last week" "X"}}` generates a UNIX timestamp from last week: 1597924480</li> </ul> |
190+
191+
A practical example of using the `{{moment}}` helper would be setting the pagination options on a typical API endpoint:
192+
193+
```
194+
GET https://api.acme.com/events?from={{moment "last week" "X"}}&to={{moment "X"}}
195+
```
196+
197+
<Info>
198+
For a full overview of date formatting option, check the [moment.js docs](https://momentjs.com/docs/#/displaying/format/).
199+
</Info>
200+
201+
In addition, you have access to these generic variables available to all checks:
202+
203+
<GenericRuntimeVariablesTable/>

detect/synthetic-monitoring/api-checks/set-up-and-tear-down.mdx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ description: 'Learn how to set up and tear down an API check with Checkly.'
55
sidebarTitle: Set Up and Tear Down
66
---
77

8+
import GenericRuntimeVariablesTable from '/snippets/generic-runtime-variables-table.mdx';
9+
810
Setup and teardown scripts can be used to execute arbitrary JavaScript/TypeScript code before and/or after an API check.
911
Both script types have access to all environment variables, runtime objects like `request` and `response` and popular npm packages
1012
like `moment`, `axios` and `lodash`.
@@ -166,7 +168,7 @@ delete process.env.SOME_OTHER_KEY
166168
In setup scripts, the modified environment object is used for the subsequent HTTP request. In teardown
167169
script, the modified environment object is just there for informational purposes.
168170

169-
[More about using environment variables](/api-checks/variables/)
171+
[More about using environment variables](/platform/variables)
170172

171173
### Request
172174

@@ -196,16 +198,18 @@ Response properties are exposed a standard Javascript object. These are only ava
196198
### Built-in runtime variables
197199

198200
[The setup and teardown runtime](/platform/runtimes/overview) also exposes a set of specific environment variables to the setup and teardown scripts,
199-
next to the "generic" runtime variables like `process.env.CHECK_NAME` you find in all check runtimes
201+
next to the "generic" runtime variables like `process.env.CHECK_NAME` you find in all check runtimes.
200202

201203
#### Setup & teardown specific variables
202204

203-
| variable | description |
205+
| Variable | Description |
204206
|------------------|------------------------------------------------------------|
205207
| `GROUP_BASE_URL` | The `{{GROUP_BASE_URL}}` value of the grouped `API` check. |
206208
| `REQUEST_URL` | The request URL of the `API` check executed. |
207209

210+
#### Generic runtime variables
208211

212+
<GenericRuntimeVariablesTable/>
209213

210214
## Included libraries
211215

detect/synthetic-monitoring/browser-checks/mac-structure.mdx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ description: 'Learn how to structure your Browser Checks with Monitoring as Code
44
sidebarTitle: MaC Structure
55
---
66

7+
import GenericRuntimeVariablesTable from '/snippets/generic-runtime-variables-table.mdx';
78

89
Monitoring as Code works by connecting Playwrighttest files with Checkly constructs to handle the end-to-endconfiguration of your Browser Check.
910

@@ -42,3 +43,39 @@ test('Environment-aware test', async ({ page }) => {
4243
})
4344
```
4445

46+
## Environment variables
47+
48+
[Check, group and global variables](/platform/variables) are accessible in your code using the standard Node.js `process.env.MY_VAR` notation. For example, the code snippet below show how you can log into GitHub.
49+
50+
<CodeGroup dropdown>
51+
52+
```ts variables.spec.ts
53+
import { test } from '@playwright/test'
54+
55+
test('GitHub login', async ({ page }) => {
56+
await page.goto('https://github.com/login')
57+
await page.getByLabel('Username or email address').type(process.env.GITHUB_USER)
58+
await page.getByLabel('Password').type(process.env.GITHUB_PWD)
59+
await page.getByRole('button', { name: 'Sign in' }).click()
60+
})
61+
```
62+
63+
```js variables.spec.js
64+
const { test } = require('@playwright/test')
65+
66+
test('GitHub login', async ({ page }) => {
67+
await page.goto('https://github.com/login')
68+
await page.getByLabel('Username or email address').type(process.env.GITHUB_USER)
69+
await page.getByLabel('Password').type(process.env.GITHUB_PWD)
70+
await page.getByRole('button', { name: 'Sign in' }).click()
71+
})
72+
```
73+
74+
</CodeGroup>
75+
76+
### Built-in runtime variables
77+
78+
Our [check runtimes](/platform/runtimes/overview/) also expose a set of environment variables (e.g. `process.env.CHECK_NAME`)
79+
to figure out what check, check type etc. you are running.
80+
81+
<GenericRuntimeVariablesTable/>

detect/synthetic-monitoring/multistep-checks/overview.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ description: 'Monitor complex API workflows with sequential requests using Playw
44
sidebarTitle: 'Overview'
55
---
66

7+
import GenericRuntimeVariablesTable from '/snippets/generic-runtime-variables-table.mdx';
8+
79
<Tip>
810
**Monitoring as Code**: Learn more about the [Multistep Check Construct](/constructs/multistep-check).
911
</Tip>
@@ -66,5 +68,6 @@ As with Browser checks, Checkly runs Multistep checks for a maximum of 240s. Scr
6668

6769
The Multistep Check [runtime](/platform/runtimes/overview) exposes a set of environment variables (e.g. `process.env.CHECK_NAME`) that indicate what check, check type etc. you are running.
6870

71+
<GenericRuntimeVariablesTable/>
6972

70-
73+
[Learn more about environment variables.](/platform/variables)

platform/variables.mdx

Lines changed: 53 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,90 @@
11
---
2-
title: 'Environment variables'
2+
title: 'Environment variables and secrets'
33
sidebarTitle: 'Environment Variables'
4-
description: 'Securely store and manage sensitive data like credentials and configuration values across your monitoring checks'
4+
description: 'Store and manage common configuration values across your checks'
55
---
66

7-
Environment variables allow you to store sensitive data like credentials and configuration values that can be reused across your monitoring setup. This keeps secrets out of your code and enables flexible configuration management.
7+
import GenericRuntimeVariablesTable from '/snippets/generic-runtime-variables-table.mdx';
88

9-
## Managing variables
9+
Your checks might share the same configuration data, like an authentication token, a user name, or even a specific part of the URL. You can use variables and secrets to 'DRY' up your checks, store these variables in one place, and keep sensitive data secure.
1010

11-
You can create environment variables at three hierarchical levels, with check-level variables taking precedence over group and global variables.
11+
## Overview
1212

13-
<Accordion title="Check-level variables">
14-
Variables defined at the check level are only available to that specific check. Use these for check-specific configuration or to override group/global variables.
13+
There are two ways to store configuration information in Checkly: Variables and secrets. Both variables and secrets are encrypted at rest and in flight.
14+
* **Variables** are used to store non-sensitive information. Variables are shown in plaintext when being edited, on the check result page and in logs. Variables can be accessed via the CLI and API.
15+
* **Secrets** allow you to store sensitive data for use in checks. Once saved, secrets are never shown in the UI or in logs and cannot be accessed via the CLI or API.
1516

16-
**Supported by:** API, Browser, Multistep & Playwright checks
17+
<Note>
18+
Secrets are fully supported starting with runtime version 2024.09 and later. For [Private Locations](/docs/private-locations/), secrets are available in agent version `3.3.4` and later, and for the [CLI](/docs/cli/), in version `4.9.0` and later.
19+
</Note>
1720

18-
Add variables on the **Variables** tab when editing a check.
21+
<Warning>
22+
To ensure the integrity of Playwright artifacts (traces, videos and screenshots), the following are not scrubbed, even when saved as secrets: The characters `/` and `*` and the full or partial match of `/artifact/`, `https://`, `http://`, `*********`, and `123`.
23+
Values of the keys `sha1`, `_sha1`, `pageref`, `downloadsPath`, `tracesDir`, `pageId` and any string that ends with `sha1` will not be scrubbed from the Playwright trace, but will be scrubbed from the general check result.
24+
Numbers are not scrubbed from the Playwright trace, but from the general check result.
25+
</Warning>
1926

20-
![check environment variables](/images/docs/images/browser-checks/check-environment-variables.png)
27+
From here on, in this document, we refer to both variables and secrets as 'variables' for ease of reading, unless explicitly mentioned.
2128

22-
**Example use cases:**
23-
- Test-specific credentials
24-
- Different API endpoints per check
25-
- Override default timeout values
26-
</Accordion>
27-
28-
<Accordion title="Group-level variables">
29-
Variables defined at the group level are inherited by all checks within that group. This is ideal for sharing common configuration across related checks.
29+
## Managing variables
3030

31-
**Benefits:**
32-
- Reduces duplication across checks in the same group
33-
- Consistent configuration for related monitoring scenarios
34-
- Easy maintenance when credentials or endpoints change
31+
You can create environment variables and secrets at three hierarchical levels:
3532

36-
**Example use cases:**
37-
- Shared service credentials for all checks in a group
38-
- Common API base URLs
39-
- Environment-specific configuration (staging vs production)
40-
</Accordion>
33+
<Accordion title="Check-level">
34+
Variables defined at the check level are only available to that specific check. Use these for check-specific configuration or to override group/global variables.
4135

42-
<Accordion title="Global variables">
43-
Variables defined at the global level are available to all checks across your entire account. Use these for organization-wide configuration.
36+
**Supported by:** API (only via the CLI), Browser, Multistep & Playwright checks
4437

45-
**Best practice:** Store variables at the global level whenever possible to follow the DRY (Don't Repeat Yourself) principle.
38+
Check-level variables are shown in the **Variables** tab on the check edit page.
4639

47-
**Example use cases:**
48-
- Organization-wide credentials
49-
- Global configuration values
50-
- Default timeout and retry settings
40+
![check environment variables](/images/docs/images/browser-checks/check-environment-variables.png)
5141
</Accordion>
5242

53-
## Variable hierarchy
43+
<Accordion title="Group-level">
44+
Group variables are only accessible in the context of a group, which includes the checks within the group and their configuration.
5445

55-
When checks run, Checkly merges variables from all three levels into a single dataset. Variables at more specific levels override those at broader levels:
46+
Group-level variables are shown the **Variables** tab in a check group.
5647

57-
**Check variables** > **Group variables** > **Global variables**
48+
![set group environment variable](/images/docs/images/browser-checks/group-environment-variables.png)
49+
</Accordion>
5850

59-
This hierarchy allows you to:
60-
- Set default values at the global or group level
61-
- Override specific values at the check level when needed
62-
- Maintain flexible configuration with minimal duplication
51+
<Accordion title="Global">
52+
Variables defined at the global level are available throughout Checkly, including in checks, alert channels, and global configuration options.
6353

64-
## Accessing variables
54+
Global variables are shown in the [Environment variables](https://app.checklyhq.com/environment-variables) section on the left-side menu.
6555

66-
Environment variables are accessible in your code using the standard Node.js `process.env.VARIABLE_NAME` notation.
56+
![set global environment variable](/images/docs/images/browser-checks/global-environment-variables.png)
6757

68-
<Accordion title="Example: GitHub login">
69-
<CodeGroup dropdown>
58+
<Note>
59+
Store variables at the global level whenever possible to follow the DRY (Don't Repeat Yourself) principle.
60+
</Note>
7061

71-
```ts variables.spec.ts
72-
import { test } from '@playwright/test'
62+
</Accordion>
7363

74-
test('GitHub login', async ({ page }) => {
75-
await page.goto('https://github.com/login')
76-
await page.getByLabel('Username or email address').type(process.env.GITHUB_USER)
77-
await page.getByLabel('Password').type(process.env.GITHUB_PWD)
78-
await page.getByRole('button', { name: 'Sign in' }).click()
79-
})
80-
```
64+
By default, all variables are stored as string values.
8165

82-
```js variables.spec.js
83-
const { test } = require('@playwright/test')
66+
When using variables, you can click the lock icon to hide the value. Any data you “lock” is encrypted at rest and in flight on our back end and is only decrypted when needed. Locked environment variables can only be accessed by team members with [Read & Write access](/admin/team-management/overview/) or above.
8467

85-
test('GitHub login', async ({ page }) => {
86-
await page.goto('https://github.com/login')
87-
await page.getByLabel('Username or email address').type(process.env.GITHUB_USER)
88-
await page.getByLabel('Password').type(process.env.GITHUB_PWD)
89-
await page.getByRole('button', { name: 'Sign in' }).click()
90-
})
91-
```
68+
Secrets are never visible for any user and are always encrypted.
9269

93-
</CodeGroup>
94-
</Accordion>
70+
## Variable hierarchy
9571

96-
## Built-in variables
72+
As checks are scheduled, Checkly merges the check, group, and global environment variables into one data set and exposes them
73+
to the runtime environment. During merging, variables at more specific levels override those at broader levels.
9774

98-
Checkly provides several built-in environment variables that are automatically available in your checks:
75+
Or, in other words: **check** variables override **group** variables override **global** variables.
9976

100-
<Accordion title="Runtime variables">
101-
- `CHECK_NAME` - The name of the current check
102-
- `CHECK_TYPE` - The type of check (API, BROWSER, etc.)
103-
- `CHECK_ID` - The unique identifier of the check
104-
- `REGION` - The current data center location (e.g., `us-east-1`)
105-
- `RUN_ID` - Unique identifier for the current check run
106-
</Accordion>
77+
You can make use of this by providing a default value for a specific variable at the global or group level, but allow that variable to
78+
be overridden at the check level.
79+
80+
## Accessing variables
10781

108-
## Security
82+
How variables are accessed depends on where you're accessing them from:
10983

110-
- **Encryption:** All variable data is encrypted at rest and in transit
111-
- **Access control:** Locked variables can only be accessed by team members with Read & Write access or above
112-
- **Best practices:** Avoid logging sensitive variables in your check results to prevent exposure to Read Only team members
84+
* In [Browser](/detect/synthetic-monitoring/browser-checks/mac-structure#environment-variables), [Multistep](/detect/synthetic-monitoring/multistep-checks/overview#built-in-runtime-variables), and [API Check setup/teardown scripts](/detect/synthetic-monitoring/api-checks/set-up-and-tear-down#built-in-variables), use the standard Node.js `process.env.VARIABLE_NAME` notation.
85+
* In [API Check requests](/detect/synthetic-monitoring/api-checks/requests#accessing-environment-variables), use Handlebars/Moustache templating delimiters, i.e. `{{VARIABLE_NAME}}`
86+
* In [webhook alert channels](/integrations/alerts/webhooks#template-variables), also use the Handlebar/Moustache format, i.e. `{{VARIABLE_NAME}}`
11387

11488
<Note>
115-
For more login scenarios and examples, see our [login scenarios documentation](/browser-checks/login-scenarios/).
89+
Handlebar (double brackets) variables will be URI encoded. To avoid encoding, you can access your environment variables with triple brackets, i.e. `{{{VARIABLE_NAME}}}`.
11690
</Note>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
| Variable | Description | Availability |
2+
|-------------------|---------------------------------------------|--------------------------------------|
3+
| `ACCOUNT_ID` | The ID of the account the check belongs to. | |
4+
| `CHECK_ID` | The UUID of the check being executed. | Only available after saving the check. |
5+
| `CHECK_NAME` | The name of the check being executed. | |
6+
| `CHECK_RESULT_ID` | The UUID where the result will be saved. | Only available on scheduled runs. |
7+
| `CHECK_RUN_ID` | The UUID of the check run execution. | Only available on scheduled runs. |
8+
| `CHECK_TYPE` | The type of the check, e.g. `BROWSER`. | |
9+
| `PUBLIC_IP_V4` | The IPv4 of the check run execution. | |
10+
| `PUBLIC_IP_V6` | The IPv6 of the check run execution. | |
11+
| `REGION` | The current region, e.g. `us-west-1`. | |
12+
| `RUNTIME_VERSION` | The version of the runtime, e.g, `2023.09`. | Only in Browser, Multistep, and API setup/teardown scripts. |

0 commit comments

Comments
 (0)