Skip to content

Commit 61e86c9

Browse files
authored
Merge pull request #72 from checkly/guolau/restore-and-update-built-in-env-vars-content
Restore missing environment variable content, plus minor fixes/updates
2 parents b4ce723 + 35b0a08 commit 61e86c9

6 files changed

Lines changed: 158 additions & 85 deletions

File tree

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

Lines changed: 42 additions & 3 deletions
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.
@@ -98,6 +98,46 @@ request, use the username and password fields in the relevant section.
9898

9999
![api monitoring basic auth](/images/docs/images/api-checks/http-request-auth.png)
100100

101+
## Accessing environment variables
102+
103+
[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}}}`.
104+
105+
Variables can be used in the following API checks fields:
106+
107+
- URL
108+
- Body
109+
- Header values
110+
- Query parameters values
111+
- Basic authentication username and password
112+
113+
### Using helpers and built-in variables
114+
115+
Next to your own variables, we've added some built-in ones.
116+
117+
These variables are specific to API checks:
118+
119+
| Helper | Description |
120+
|----------------------|------------ |
121+
| `{{GROUP_BASE_URL}}` | If your check belongs to a group, this resolves to the group's configured base URL. |
122+
| `{{REQUEST_URL}}` | The request URL. |
123+
| `{{$UUID}}` | Generates a random UUID/v4, i.e. 9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d. |
124+
| `{{$RANDOM_NUMBER}}` | Generates a random decimal number between 0 and 10000, i.e. 345. |
125+
| `{{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> |
126+
127+
A practical example of using the `{{moment}}` helper would be setting the pagination options on a typical API endpoint:
128+
129+
```
130+
GET https://api.acme.com/events?from={{moment "last week" "X"}}&to={{moment "X"}}
131+
```
132+
133+
<Info>
134+
For a full overview of date formatting option, check the [moment.js docs](https://momentjs.com/docs/#/displaying/format/).
135+
</Info>
136+
137+
In addition, you have access to these generic variables available to all checks:
138+
139+
<GenericRuntimeVariablesTable/>
140+
101141
## Import a cURL request
102142

103143
You can import the request method, url, headers and body from a [cURL](https://curl.haxx.se/) command.
@@ -160,5 +200,4 @@ This list shows all content types that we scrub from the response data.
160200
|`video/x-ms-wmv`|
161201
|`video/x-msvideo`|
162202
|`video/x-flv`|
163-
|`video/webm`|
164-
203+
|`video/webm`|

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: 56 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,94 @@
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+
<Tip>
28+
This page provides a general overview of environment variables. For information specific to the CLI, refer to our [Checkly CLI documentation](/cli/environment-variables).
29+
</Tip>
2130

22-
**Example use cases:**
23-
- Test-specific credentials
24-
- Different API endpoints per check
25-
- Override default timeout values
26-
</Accordion>
31+
From here on, in this document, we refer to both variables and secrets as 'variables' for ease of reading, unless explicitly mentioned.
2732

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.
33+
## Managing variables
3034

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
35+
You can create environment variables and secrets at three hierarchical levels:
3536

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>
37+
<Accordion title="Check-level">
38+
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.
4139

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.
40+
**Supported by:** API (only via the CLI), Browser, Multistep & Playwright checks
4441

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

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

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

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:
50+
Group-level variables are shown the **Variables** tab in a check group.
5651

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

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
55+
<Accordion title="Global">
56+
Variables defined at the global level are available throughout Checkly, including in checks, alert channels, and global configuration options.
6357

64-
## Accessing variables
58+
Global variables are shown in the [Environment variables](https://app.checklyhq.com/environment-variables) section on the left-side menu.
59+
60+
![set global environment variable](/images/docs/images/browser-checks/global-environment-variables.png)
6561

66-
Environment variables are accessible in your code using the standard Node.js `process.env.VARIABLE_NAME` notation.
62+
<Note>
63+
Store variables at the global level whenever possible to follow the DRY (Don't Repeat Yourself) principle.
64+
</Note>
6765

68-
<Accordion title="Example: GitHub login">
69-
<CodeGroup dropdown>
66+
</Accordion>
7067

71-
```ts variables.spec.ts
72-
import { test } from '@playwright/test'
68+
By default, all variables are stored as string values.
7369

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-
```
70+
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.
8171

82-
```js variables.spec.js
83-
const { test } = require('@playwright/test')
72+
Secrets are never visible for any user and are always encrypted.
8473

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-
```
74+
## Variable hierarchy
9275

93-
</CodeGroup>
94-
</Accordion>
76+
As checks are scheduled, Checkly merges the check, group, and global environment variables into one data set and exposes them
77+
to the runtime environment. During merging, variables at more specific levels override those at broader levels.
9578

96-
## Built-in variables
79+
Or, in other words: **check** variables override **group** variables override **global** variables.
9780

98-
Checkly provides several built-in environment variables that are automatically available in your checks:
81+
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
82+
be overridden at the check level.
9983

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>
84+
## Accessing variables
10785

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

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
88+
* 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.
89+
* In [API Check requests](/detect/synthetic-monitoring/api-checks/requests#accessing-environment-variables), use Handlebars/Moustache templating delimiters, i.e. `{{VARIABLE_NAME}}`
90+
* In [webhook alert channels](/integrations/alerts/webhooks#template-variables), also use the Handlebar/Moustache format, i.e. `{{VARIABLE_NAME}}`
11391

11492
<Note>
115-
For more login scenarios and examples, see our [login scenarios documentation](/browser-checks/login-scenarios/).
93+
Handlebar (double brackets) variables will be URI encoded. To avoid encoding, you can access your environment variables with triple brackets, i.e. `{{{VARIABLE_NAME}}}`.
11694
</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)