To get notified when there's an "ERROR" log in Google Cloud Logging for each running Cloud Function, you can set up a log-based metric and then create a notification using Cloud Monitoring. Here's how:
Create a Log-Based Metric:
Go to the Google Cloud Console.
Navigate to "Logging" under "Operations".
In the left navigation pane, click on "Logs Viewer".
Enter your log query, such as resource.type="cloud_function" severity="ERROR".
Click "Create Metric" and give it a name.
Create an Alerting Policy:
Go to "Monitoring" in the Google Cloud Console.
Click "Alerting" in the left navigation pane.
Click "Create Policy".
In the "Add Condition" section, select "Logs-based metric" and then select the metric you created earlier.
Configure the condition based on your requirements (e.g., condition threshold).
In the "Notifications" section, add the appropriate notification channels (email, SMS, etc.).
Save the policy.
Test the Alert:
Introduce an error in one of your Cloud Functions.
Wait for the error to trigger the log entry.
Cloud Monitoring will evaluate the condition and send notifications if the condition is met.
This setup ensures you receive notifications whenever there's an "ERROR" log in the Google Cloud Logging for your running Cloud Functions.