Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 36 additions & 43 deletions content/en/synthetics/notifications/advanced_notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,6 @@ To display raw values without HTML escaping (for example, URLs, or HTTP response

<div class="alert alert-info">Certain messaging integrations (such as Google) require triple braces <code>&#123;&#123;&#123;</code> around template variables to ensure proper formatting when the message is displayed. For example, you can use <code>&#123;&#123;&#123;synthetics.attributes.result.failure.message&#125;&#125;&#125;</code>.</div>

You can loop over lists (like steps or variables) or access items directly:

```handlebars
{{list.2.name}} {{! third item }}
{{list.-1.status}} {{! last item }}
{{list[My Complex Name]url}} {{! use bracket notation for complex keys }}
{{list[My Complex Name]failure.code}}
{{list.abc-def-ghi}} {{! access via ID (case-insensitive) }}
```

### Human-readable formatting

**Note**: All durations are in milliseconds.
Expand Down Expand Up @@ -80,6 +70,9 @@ You can loop over lists (like steps or variables) or access items directly:
### Conditional alerting based on step ID

```handlebars
{{!
This alert uses the variable shortcut object `{{synthetics.failed_step}}` to match the step id. If the step id matches, notify the relevant recipient.
}}
{{#is_exact_match synthetics.failed_step.id "svn-yrx-3xg"}}
A backend-related step failed!
@slack-backend-team
Expand All @@ -98,55 +91,55 @@ Use `#each` to loop over dictionaries or lists. You can access:
- `@key` → the current key (for dictionaries)
- `@index`, `@first`, `@last` → loop metadata

#### Dictionary example:
### Use local variables in a notification

```handlebars
{{#each users}}
# User `{{@key}}`
Name: {{name}}
Permissions: {{permissions}}
{{/each}}

Users: {{#each users}}`{{@key}}` ({{name}}){{#unless @last}}, {{/unless}}{{/each}}
{{!
The test is configured with three local variables.
The names of the variables are: APP_NAME, APP_URL, and APP_ENVIRONMENT.
The value of the variable can be accessed by passing its name in the config field like `{{synthetics.attributes.result.variables.config[<variable-name>].value}}`
}}
Application: {{synthetics.attributes.result.variables.config[APP_NAME].value}}
URL Tested: {{synthetics.attributes.result.variables.config[APP_URL].value}}
Environment: {{synthetics.attributes.result.variables.config[APP_ENVIRONMENT].value}}
```

### Use local (config) variables in a notification
### Loop through the steps of a multistep API test

```handlebars
Synthetic Test Failed!

Application: {{ synthetics.attributes.result.variables.config[APP_NAME].value }}
URL Tested: {{ synthetics.attributes.result.variables.config[APP_URL].value }}
Random value: {{ synthetics.attributes.result.variables.config[NAME].value }}
{{! Print out the details of each step }}
{{#each synthetics.attributes.result.steps}}
Step name: {{name}}
Step status: {{status}}
Step type: {{type}}

Test: {{ synthetics.attributes.test.name }} ({{ synthetics.attributes.test.id }})
Failed step: {{ synthetics.failed_step.name }}
Location: {{ synthetics.attributes.location.id }}
Result: {{ synthetics.result_url }}
{{! Within each step, print out the details of the extracted variable }}
{{#each variables.extracted}}
Extracted variable name: {{ name }}
Extracted variable value: {{ val }}
{{/each}}

@your-email
{{/each}}
```

<div class="alert alert-tip">To loop through all config variables and print their values safely:

### Loop through the steps of a browser test
```handlebars
{{#each synthetics.attributes.result.variables.config}}
- {{@key}}: {{#if this.secure}}[secure]{{else}}{{this.value}}{{/if}}
{{/each}}
```
{{! Print out the details of each step }}
{{#each synthetics.attributes.result.steps}}

</div>
Step name: {{description}}
Step status: {{status}}
Step type: {{type}}

## Steps loop
{{! Print out the details of the extracted variable step }}
{{#is_match "type" "extractVariable"}}
Extracted variable name: {{ extractedValue.name }}
Extracted variable value: {{ extractedValue.value }}
{{/is_match}}

```handlebars
{{#each synthetics.attributes.result.steps}}
* Step name: {{description}}
* Step status: {{status}}
* Step type: {{type}}
{{/each}}
```

## Further Reading

{{< partial name="whats-next/whats-next.html" >}}
{{< partial name="whats-next/whats-next.html" >}}
72 changes: 59 additions & 13 deletions content/en/synthetics/notifications/conditional_alerting.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,78 @@ For more detailed information, see the <a href="https://docs.datadoghq.com/monit

### Examples

**Send alerts based on status code:**

```handlebars
{{!
If a test triggers an alert for an API test and returns a 500 statuscode, notify the backend team.
}}
{{#is_alert}}
{{#is_exact_match "synthetics.attributes.result.response.statusCode" "500"}}@notify-slack-backend{{/is_exact_match}}
{{/is_alert}}
```

**Send alerts to a specific Slack channel based on failed step:**

```handlebars
{{#is_match "synthetics.failed_step.description" "Checkout"}}
@notify-slack-payments
{{/is_match}}
{{!
If a test triggers an alert for browser or mobile tests, loop through each step and find the failed step.
If the failed step's description field matches Checkout, notify the recipient
}}
{{#is_alert}}
{{#each synthetics.attributes.result.steps}}
{{#is_match "status" "failed"}}
{{#is_match "description" "Checkout"}}@notify-slack-payments{{/is_match}}
{{/is_match}}
{{/each}}
{{/is_alert}}
```

**Send alerts based on status code:**
**Send alerts to a specific Slack channel based on failed step using a variable shortcut:**

```handlebars
{{#is_exact_match "synthetics.attributes.result.response.statusCode" "500"}}
@notify-slack-backend
{{/is_exact_match}}
{{!
This alert uses the `{{synthetics.failed_step}}` object which is a variable shortcut that points to the relevant step data contained in `{{synthetics.attributes.result.steps}}`.
If the test triggers an alert for browser or mobile tests, and if the failed step's description field matches Checkout, notify the recipient.
}}
{{#is_alert}}
{{#is_match "synthetics.failed_step.description" "Checkout"}}@notify-slack-payments{{/is_match}}
{{/is_alert}}
```

**Set different alert priorities:**

```handlebars
{{#if synthetics.failed_step.name}}
{{override_priority "P2"}}
{{else}}
{{override_priority "P4"}}
{{/if}}
{{!
If a test triggers an alert for a multistep API test, loop through each step and find the failed step.
If the step's name matches the staging domain, set the priority to P2. Otherwise, set it to P4.
}}
{{#is_alert}}send a message to thang @thang.nguyen@datadoghq.com
{{#each synthetics.attributes.result.steps}}
{{#is_match "status" "failed"}}
{{#is_match "name" "stagedomain"}}Stage domain failed. Overriding priority to P2.
{{override_priority 'P2'}}
{{else}}Dev domain failed. Overriding priority to P4{{override_priority 'P4'}}
{{/is_match}}
{{/is_match}}
{{/each}}
{{/is_alert}}
```

**Set different alert priorities using variable shortcut:**

```handlebars
{{!
This alert uses the `{{synthetics.failed_step}}` object which is a variable shortcut that points to the relevant step data contained in `{{synthetics.attributes.result.steps}}`.
If the test triggers an alert for multistep API test and if the failed step's name field matches the domain, override the priority.
}}
{{#is_alert}}
{{#is_match "synthetics.failed_step.name" "stagedomain"}}Stage domain failed. Overriding priority to P2{{override_priority 'P2'}}
{{else}}Dev domain failed. Overriding priority to P4{{override_priority 'P4'}}
{{/is_match}}
{{/is_alert}}
```

## Further Reading

{{< partial name="whats-next/whats-next.html" >}}
{{< partial name="whats-next/whats-next.html" >}}
88 changes: 53 additions & 35 deletions content/en/synthetics/notifications/template_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,48 +52,60 @@ Test failed at step {{synthetics.failed_step.name}} with error: {{synthetics.fai
{{< tabs >}}
{{% tab "Test Info" %}}

`.test`
: Info about the test
`{{synthetics.attributes.test}}`
: The `test` object contains information about the test like its `name`, `type`, `subtype`, and `id`

`.test.id`
: Public ID (for example, `abc-def-ghi`)
`{{synthetics.attributes.test.name}}`
: The name of the test

`.test.type`
`{{synthetics.attributes.test.type}}`
: Test type (for example, `api`)

`.test.subType`
: Subtype for API tests (for example, `http`)
`{{synthetics.attributes.test.subType}}`
: Subtype for API tests (for example, `http`, `dns`, and `multi`)

`{{synthetics.attributes.test.id}}`
: The test's public ID (for example, `abc-def-ghi`)

{{% /tab %}}
{{% tab "Location" %}}

`.location.id`
`{{synthetics.attributes.location}}`
: The `location` object contains information about the location of where the test is run from

`{{synthetics.attributes.location.id}}`
: Location ID (for example, `aws:eu-central-1`)

`.location.privateLocation`
`{{synthetics.attributes.location.name}}`
: Name of the location (for example, `Frankfurt (AWS)`)

`{{synthetics.attributes.location.privateLocation}}`
: `true` for Private Locations

{{% /tab %}}
{{% tab "Device" %}}

Applies to browser and mobile tests.

`.device.id`
`{{synthetics.attributes.device}}`
: The `device` object contains information about the device on which the test is run on

`{{synthetics.attributes.device.id}}`
: Device identifier

`.device.name`
`{{synthetics.attributes.device.name}}`
: Human-readable device name

`.device.type`
`{{synthetics.attributes.device.type}}`
: Device type classification

`.device.resolution.width`, `.device.resolution.height`
`{{synthetics.attributes.device.width}}`, `{{synthetics.attributes.device.height}}`
: Screen resolution dimensions

`.device.browser.type`
`{{synthetics.attributes.device.browser.type}}`
: Browser type (browser tests only)

`.device.platform.name`, `.device.platform.version`
`{{synthetics.attributes.device.platform.name}}`, `{{synthetics.attributes.device.platform.version}}`
: Platform information (mobile tests only)

**Example values:**
Expand All @@ -113,23 +125,29 @@ Applies to browser and mobile tests.
{{% /tab %}}
{{% tab "Result" %}}

`.result.id`
`{{synthetics.attributes.result}}`
: The `result` object contains information about the executed test run

`{{synthetics.attributes.result.id}}`
: Unique result ID

`.result.status`
: Test execution status
`{{synthetics.attributes.result.status}}`
: Test execution status (for example, `passed` or `failed`)

`.result.duration`
`{{synthetics.attributes.result.duration}}`
: Test duration in milliseconds

`.result.testStartedAt`, `.result.testFinishedAt`, `.result.testTriggeredAt`
`{{synthetics.attributes.result.testStartedAt}}`, `{{synthetics.attributes.result.testFinishedAt}}`, `{{synthetics.attributes.result.testTriggeredAt}}`
: Epoch timestamps in milliseconds

`.result.failure.message`
: Description of failure
`{{synthetics.attributes.result.failure}}`
: The `failure` object contains information about why the test failed

`.result.failure.code`
: Error code
`{{synthetics.attributes.result.failure.message}}`
: The failure message

`{{synthetics.attributes.result.failure.code}}`
: The failure code

**Example values:**
```json
Expand Down Expand Up @@ -161,16 +179,16 @@ These are local variables configured for API tests or defined outside individual

Located at `{{synthetics.attributes.result.variables.config}}`:

`.name`
`{{synthetics.attributes.result.variables.config.name}}`
: Variable name

`.type`
`{{synthetics.attributes.result.variables.config.type}}`
: Variable type

`.secure`
`{{synthetics.attributes.result.variables.config.secure}}`
: Whether the variable value is obfuscated

`.value`
`{{synthetics.attributes.result.variables.config.value}}`
: Variable value (non-obfuscated only)

**Examples:**
Expand All @@ -190,18 +208,18 @@ These are extracted variables whose value updates a global variable value.

Available only for **successful test results** and **recovery notifications**.

Located at `result.variables.extracted`:
Located at `{{synthetics.attributes.result.variables.extracted}}`:

`.id`
`{{synthetics.attributes.result.variables.extracted.id}}`
: Global variable ID

`.name`
`{{synthetics.attributes.result.variables.extracted.name}}`
: Variable name

`.secure`
`{{synthetics.attributes.result.variables.extracted.secure}}`
: Whether the variable value is obfuscated

`.val`
`{{synthetics.attributes.result.variables.extracted.val}}`
: Variable value (note: uses `.val`, not `.value`)

**Examples:**
Expand All @@ -217,7 +235,7 @@ Located at `result.variables.extracted`:
{{% /tab %}}
{{% tab "Step extracted variables" %}}

For tests with steps, step data is contained in `.steps`.
For tests with steps, step data is contained in `{{synthetics.attributes.result.steps}}`.

`.extractedValue.name`
: Variable name
Expand Down Expand Up @@ -319,7 +337,7 @@ Similar to standard API tests, the variables are listed in the `variables.extrac

**General:**

`.startUrl`
`{{synthetics.attributes.result.startUrl}}`
: URL from test configuration

**Steps:**
Expand Down
Loading