Annotate notifications with user-defined documentation

This page describes how you can configure your alerting policy documentationso that notifications provide incident responders with resources andadditional information for incident resolution.

Documentation structure

The documentation of an alerting policy consists of a subject, content,and links. You can configure documentation in the Google Cloud console, theCloud Monitoring API, and the Google Cloud CLI.

Subjects

Thesubject of your documentation appears in the subject ofnotifications for incidents related to your alerting policy.Notification recipients can manage and sort their notifications by subject.

Subject lines are limited to 255 characters. If you don't define a subject inyour documentation, then Cloud Monitoring determines the subject line.Subject lines support plain text andvariables.

Cloud Monitoring API

Configure the notification subject line by using thesubject fieldof the alerting policydocumentation.

Google Cloud console

Configure the notification subject line by using theNotification subject line field in theNotifications and name section of theCreate alerting policy page.

Content

Thecontent of your documentation appears in the following notificationtypes:

  • Email, in thePolicy Documentation section
  • PagerDuty
  • Pub/Sub
  • Slack
  • Webhooks

We recommend configuring your content so that incidentresponders can view remediation steps and incident information innotifications related to your alerting policy. For example, you might configurethe documentation to include a summary of the incident andinformation about relevant resources.

Documentation content supports the following:

Cloud Monitoring API

Configure documentation content by using thecontent fieldof the alerting policydocumentation.

Google Cloud console

Configure documentation content by using theDocumentation field in theNotifications and name section of theCreate alerting policy page.

Links

You can add links to your documentation so that incident responders canaccess resources such as playbooks, repositories, and Google Cloud dashboardsfrom a notification.

The Cloud Monitoring API lets you define an object that contains the most relevantlinks for responders. While the Google Cloud console doesn't have a fieldspecifically for links, you can add a section for links in your documentationbody.

Cloud Monitoring API

You can add links to your documentation by defining one or moreLink objects in thelinks field of the alerting policydocumentation. EachLink object consists of adisplay_name and aurl. You can have up to three links inyour documentation.

The following configuration shows thelinks field with oneLink objectrepresenting a URL to an incident playbook. The URL includes a variableso that notification recipients can access the correct playbook based on themonitored resource where the incident occurred:

"links"[{"displayName":"Playbook","url":"https://myownpersonaldomain.com/playbook?name=${resource.type}"}]

Documentation links added using theLink field appear in the followingnotification types:

  • Email, in theQuick Links section
  • PagerDuty
  • Pub/Sub
  • Webhooks

Google Cloud console

You can add links to your documentation content by including themin theDocumentation field of your alerting policy. For example, thefollowing documentation lists a URL for a customer playbook:

### Troubleshooting and Debug ReferencesPlaybook: https://myownpersonaldomain.com/playbook?name=${resource.type}

Documentation links added using the Google Cloud console appear with therest of your documentation content in the following notification types:

  • Email, in thePolicy Documentation section
  • PagerDuty
  • Pub/Sub
  • Slack
  • Webhooks

Markdown in documentation content

You can use Markdown to format your documentation content.Documentation content supports the following subset of Markdown tagging:

  • Headers, indicated by initial hash characters.
  • Unordered lists, indicated by initial plus, minus, or asterisk characters.
  • Ordered lists, indicated by an initial number followed by a period.
  • Italic text, indicated by single underscores or asterisks around a phrase.
  • Bold text, indicated by double underscores or asterisks around a phrase.
  • Links, indicated by[link text](url) syntax. To addlinks to your notification, we recommend that you use theCloud Monitoring API and configure theLink object.

For more information about this tagging, see any Markdown reference,for example,Markdown guide.

Variables in documentation

To customize the text in your documentation, you can use variablesof the form${varname}. When the documentation is sent witha notification, the string${varname} is replaced with a value drawn from thecorresponding Google Cloud resource, as described in the following table.

VariableValue
condition.nameThe REST resource name of the condition, such as
projects/foo/alertPolicies/1234/conditions/5678.
condition.display_nameThe display name of a condition, such asCPU usage increasing rapidly.
log.extracted_label.KEY The value of the labelKEY, extracted from a log entry. For log-based alerting policies only; for more information, see Create a log-based alerting policy by using the Monitoring API.
metadata.system_label.KEYThe value of the system-supplied resource metadata labelKEY.1
metadata.user_label.KEYThe value of the user-defined resource metadata labelKEY.1,3
metric.typeThe metric type, such as
compute.googleapis.com/instance/cpu/utilization.
metric.display_nameThe display name for the metric type, such asCPU utilization.
metric.label.KEY

The value of the metric labelKEY.1
To find the labels associated with the metric type, seeMetric list.

When the value of the variable${metric.label.KEY} doesn't start with a digit, a letter, a forward slash (/), or an equal sign (=), Monitoring omits the label from notifications.

When youmigrate a Prometheus alerting rule, the Prometheus alert field templates{{$value}} and{{humanize $value}} appear as${metric.label.value} in the alerting policy documentation configuration. In this case,${metric.label.value} holds the trigger value of the Prometheus alerting rule.

You can also use${metric.label.value} when you create PromQL queries in Google Cloud.

metric.label.metadata_system_VALUE

References a PromQL metadata system label, whereVALUE is the specific label name, such asregion orversion.

Example usage:${metric.label.metadata_system_version}.

metric.label.metadata_user_VALUE

References a PromQL metadata user label, whereVALUE is the specific label name, such asregion orname.

Example usage:${metric.label.metadata_user_name}.

metric_or_resource.labels

This variable renders all metric and resource label values as a sorted list ofkey-value pairs. If a metric label and a resource label have the same name, then only the metric label is rendered.

When youmigrate a Prometheus alerting rule, the Prometheus alert field templates{{$labels}} and{{humanize $labels}} appear as${metric_or_resource.labels} in the alerting policy documentation configuration.

metric_or_resource.label.KEY
  • IfKEY is a valid label, then this variable renders in the notification as the value of${metric.label.KEY}.
  • IfKEY is a valid resource, then this variable renders in the notification as the value of${resource.label.KEY}.
  • IfKEY is neither a valid label nor a valid resource, then this variable renders in the notification as an empty string.

When youmigrate a Prometheus alerting rule, the Prometheus alert field templates{{$labels.KEY}} and{{humanize $labels.KEY}} appear as${metric_or_resource.labels.KEY} in the alerting policy documentation configuration.

policy.nameThe REST resource name of the policy, such asprojects/foo/alertPolicies/1234.
policy.display_nameThe display name of a policy, such asHigh CPU rate of change.
policy.user_label.KEYThe value of the user labelKEY.1

Keys must start with a lowercase letter. Keys and values can contain only lowercase letters, digits, underscores, and dashes.

projectThe ID of the scoping project of a metrics scope, such asa-gcp-project.
resource.typeThe monitored-resource type, such asgce_instance.
resource.projectThe project ID of the monitored resource of the alerting policy.
resource.label.KEY The value of the resource labelKEY.1,2,3
To find the labels associated with the monitored-resource type, seeResource list.

1 For example,${resource.label.zone} is replaced withthe value of thezone label. The values of these variables are subject togrouping; seenull values for more information.
2 To retrieve the value of theproject_id label on amonitored resource in the alerting policy, use${resource.project}.
3 You can't access user-defined resource metadata labels byusingresource.label.KEY. Usemetadata.user_label.KEYinstead.

Usage notes

  • Only the variables in the table are supported. You can't combine them intomore complex expressions, like${varname1 + varname2}.
  • To include the literal string${ in your documentation, escape the$symbol with a second$ symbol, and$${ renders as${ in yourdocumentation.
  • These variables are replaced by their values only in notifications sentthrough notification channels. In the Google Cloud console, when thedocumentation is shown, you see the variables, not the values. Examplesin the console include the descriptions of incidents and the preview ofthe documentation when creating an alerting policy.
  • Verify that the aggregation settings of the condition don't eliminate thelabel. If the label is eliminated, then the value of the label in thenotification isnull. For more information,seeVariable for a metric label is null.
Note: Labels that you add to log-based metrics can't be used in templateexpressions. However, you can display these labels in chart legends andyou can filter time series by the label values.

null values

Values for themetric.*,resource.* andmetadata.* variablesare derived from time series. Their values can benull if no values arereturned from the time series query.

Variable resolution

Variables in documentation templates are resolved only in the notificationssent by using the following notification channels:

  • Email
  • Google Chat
  • Slack
  • Pub/Sub, JSON schema version 1.2
  • Webhooks, JSON schema version 1.2
  • PagerDuty, JSON schema version 1.2
Note: Variables are not resolved, but appear as strings like${varname},in other contexts, in notifications sent by using other notificationchannels.

Channel controls

The text in the documentation field can also include special characters usedby the notification channel itself to control formatting and notifications.

For example, Slack uses@ for mentions. You can use@ to link thenotification to a specific user ID. Mentions can't include names.Suppose you include a string like this in the documentation field:

<@backendoncall>Incidentcreatedbasedonpolicy${policy.display_name}

When the documentation field is received by the relevant Slack channel as partof the notification, the previous string causes Slack to send anadditional message to the user IDbackendoncall. The message sent by Slack to the usercould contain relevant information from the notification; for example,"Incident created based on policy High CPU rate of change".

These additional options are specific to the channels; for more informationon what may be available, consult the documentation provided by the channelvendor.

Example

The following example shows Google Cloud console and Cloud Monitoring API versions oftemplate documentation for a CPU utilization alerting policy.These examples use an email for thenotification channel type.The documentation templates include several variables to summarize theincident and to reference the alerting policy and condition RESTresources.

Cloud Monitoring API

"documentation":{"content":"### CPU utilization exceeded\n\n### Summary\n\nThe ${metric.display_name} of the ${resource.type} ${resource.label.instance_id} in the project ${resource.project} has exceeded 5% for over 60 seconds.\n\n#### Additional resource information\n\nCondition resource name: ${condition.name}  \nAlerting policy resource name: ${policy.name}","mimeType":"text/markdown","subject":"Alert: ${metric.display_name} exceeded","links":[{"displayName":"Playbook","url":"https://myownpersonaldomain.com/playbook?name=${resource.type}"},{"displayName":"Repository with debug scripts","url":"https://altostrat.com"},{"displayName":"Google Cloud dashboard","url":"https://example.com"}]}

The following image shows how this template appears in an emailnotification:

Example of how documentation renders in a notification. Links are shown in the 'Quick Links' section.

Google Cloud console

### CPU utilization exceeded#### SummaryThe ${metric.display_name} of the ${resource.type}${resource.label.instance_id} in the project ${resource.project} hasexceeded 5% for over 60 seconds.#### Additional resource informationCondition resource name: ${condition.name}  Alerting policy resource name: ${policy.name}  #### Troubleshooting and Debug ReferencesPlaybook: https://myownpersonaldomain.com/playbook?name=${resource.type}  Repository with debug scripts: https://altostrat.com  ${resource.type} dashboard: https://example.com

The following image shows how this template appears in an emailnotification:

Example of how documentation renders in a notification. Links are shown under a 'Troubleshooting and Debug References' header.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.