'Customize Error Reporting using Structured Logs and Monitoring/Alerting on GCP
I've added structured error reporting to my Google Cloud Function like mentioned here: https://cloud.google.com/functions/docs/monitoring/logging#writing_structured_logs. I'm wondering if I can specify fields using this technique that I can then use in the markdown of the Alerting policy:https://cloud.google.com/monitoring/alerts/doc-variables?authuser=6#doc-vars. Based on the documentation at both of these links, I'm not sure if there's any overlap though both mention labels of some sort. Ideally I would just get the message that I specify and that shows up in the logs as that has a good amount of information.
Solution 1:[1]
NOTE Error Reporting is a distinct Google service. You can use it too with a Node.JS runtime on Cloud Functions.
Alerting is based upon Monitoring and you can create so-called Log-based Metrics which are Monitoring metrics derived from Logs. Both permit labels. Log-based Metrics aggregate log entries and the labels are used as a dimension for the resulting metric.
So you can:
- Create Log-based Metrics from your (structured) logs using (some subset) of the log labels
- Create an Alerting policy on the Log-based Metric(s) using (some subset) of the labels in the documentation.
I was unaware of the Alerting policy documentation facility before your question but I'm confident you can get close to what you're after.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | DazWilkin |
