Cloud Monitoring alerting policies let you track Cloud Trace monthly span
volume, API quota limits, and span ingestion rates so that you receive
notifications before exceeding quotas or incurring unexpected ingestion costs.
If you're new to alerting, see
[Create and manage alerting policies](https://docs.cloud.google.com/monitoring/alerts/using-alerting-ui.md.txt).

For information about how to monitor the result of a SQL query that you run in
Observability Analytics, see
[Monitor your SQL query results with an alerting policy](https://docs.cloud.google.com/trace/docs/sql-in-alerting.md.txt).

## Monitor over-quota Cloud Trace API usage

To create an alerting policy that triggers when your monthly
[Cloud Trace](https://docs.cloud.google.com/trace/docs.md.txt) spans ingested
exceeds your quota, use the following settings.

#### Steps to create an [alerting policy](https://docs.cloud.google.com/monitoring/alerts/using-alerting-ui.md.txt#create-policy).

To create an alerting policy, do the following:

1. In the Google Cloud console, go to the
   **Alerting** page:

   [Go to **Alerting**](https://console.cloud.google.com/monitoring/alerting)

   <br />

   If you use the search bar to find this page, then select the result whose subheading is
   **Monitoring**.
2. If you haven't created your notification channels and if you want to be notified, then click **Edit Notification Channels** and add your notification channels. Return to the **Alerting** page after you add your channels.
3. From the **Alerting** page, select **Create policy**.
4. To select the resource, metric, and filters, expand the **Select a metric** menu and then use the values in the **New condition** table:
   1. Optional: To limit the menu to relevant entries, enter the resource or metric name in the filter bar.
   2. Select a **Resource type** . For example, select **VM instance**.
   3. Select a **Metric category** . For example, select **instance**.
   4. Select a **Metric** . For example, select **CPU Utilization**.
   5. Select **Apply**.
5. Click **Next** and then configure the alerting policy trigger. To complete these fields, use the values in the **Configure alert trigger** table.
6. Click **Next**.
7. Optional: To add notifications to your alerting policy, click
   **Notification channels** . In the dialog, select one or more notification
   channels from the menu, and then click **OK**.

   To be notified when alerts are opened and closed, check
   **Notify on alert closure**. By default, notifications are sent only when
   alerts are opened.
8. Optional: Update the **Alert autoclose duration**. This field determines when Monitoring closes alerts in the absence of metric data.
9. Optional: Click **Documentation**, and then add any information that you want included in a notification message.
10. Click **Alert name** and enter a name for the alerting policy.
11. Click **Create Policy**.

| **New condition** Field | Value |
|---|---|
| **Resource and Metric** | In the **Resources** menu, select **Consumed API** . In the **Metric categories** menu, select **Api** . In the **Metrics** menu, select **Request count** . (The metric.type is `serviceruntime.googleapis.com/api/request_count`). |
| **Filter** | `service = cloudtrace.googleapis.com response_code = 429` |
| **Across time series Time series aggregation** | `sum` |
| **Rolling window** | `1 m` |
| **Rolling window function** | `sum` |

| **Configure alert trigger** Field | Value |
|---|---|
| **Condition type** | `Threshold` |
| **Alert trigger** | `Any time series violates` |
| **Threshold position** | `Above threshold` |
| **Threshold value** | `0` |
| **Retest window** | `1 minute` |

## Monitor monthly span ingestion

To create an alerting policy that triggers when your monthly
[Cloud Trace](https://docs.cloud.google.com/trace/docs.md.txt) spans ingested
exceeds a user-defined limit, use the following settings.

#### Steps to create an [alerting policy](https://docs.cloud.google.com/monitoring/alerts/using-alerting-ui.md.txt#create-policy).

To create an alerting policy, do the following:

1. In the Google Cloud console, go to the
   **Alerting** page:

   [Go to **Alerting**](https://console.cloud.google.com/monitoring/alerting)

   <br />

   If you use the search bar to find this page, then select the result whose subheading is
   **Monitoring**.
2. If you haven't created your notification channels and if you want to be notified, then click **Edit Notification Channels** and add your notification channels. Return to the **Alerting** page after you add your channels.
3. From the **Alerting** page, select **Create policy**.
4. To select the resource, metric, and filters, expand the **Select a metric** menu and then use the values in the **New condition** table:
   1. Optional: To limit the menu to relevant entries, enter the resource or metric name in the filter bar.
   2. Select a **Resource type** . For example, select **VM instance**.
   3. Select a **Metric category** . For example, select **instance**.
   4. Select a **Metric** . For example, select **CPU Utilization**.
   5. Select **Apply**.
5. Click **Next** and then configure the alerting policy trigger. To complete these fields, use the values in the **Configure alert trigger** table.
6. Click **Next**.
7. Optional: To add notifications to your alerting policy, click
   **Notification channels** . In the dialog, select one or more notification
   channels from the menu, and then click **OK**.

   To be notified when alerts are opened and closed, check
   **Notify on alert closure**. By default, notifications are sent only when
   alerts are opened.
8. Optional: Update the **Alert autoclose duration**. This field determines when Monitoring closes alerts in the absence of metric data.
9. Optional: Click **Documentation**, and then add any information that you want included in a notification message.
10. Click **Alert name** and enter a name for the alerting policy.
11. Click **Create Policy**.

| **New condition** Field | Value |
|---|---|
| **Resource and Metric** | In the **Resources** menu, select **Global** . In the **Metric categories** menu, select **Billing** . In the **Metrics** menu, select **Monthly trace spans ingested**. |
| **Filter** |   |
| **Across time series Time series aggregation** | `sum` |
| **Rolling window** | `60 m` |
| **Rolling window function** | `max` |

| **Configure alert trigger** Field | Value |
|---|---|
| **Condition type** | `Threshold` |
| **Alert trigger** | `Any time series violates` |
| **Threshold position** | `Above threshold` |
| **`Threshold value`** | You determine the acceptable value. |
| **Retest window** | Minimum acceptable value is 30 minutes. |

## Monitor rate of span ingestion

You can also monitor the rate at which spans are ingested. To monitor ingestion
rates, select the metric type **Trace spans ingested** . The default
settings in the **Transform data** and **Across time series** sections are
appropriate for this metric type.