iTranslated by AI
Notifying Slack on Error Logs Using Google Cloud Log-Based Alerts
Sending Slack notifications for error logs output to Cloud Logging has become much easier.
This is a Google Cloud blog post published on July 27, 2021.
According to the blog, it seems to be a feature that allows you to detect logs that match specific queries from Cloud Logging and send notifications for them.

Source: Log-based alerting is now available in preview
Until now
Before this was possible, you had to implement a workflow like: Cloud Logging => Log Router => Cloud Pub/Sub => Cloud Functions => Notification.

Source: Detect and respond to Cloud Logging events in real-time
With this release, you can perform notifications without having to set up Cloud Pub/Sub or Cloud Functions.
Trying out the new feature from detection to Slack notification
Let's try using this new feature for detection and notification. For verification purposes—though you probably wouldn't do this in a real environment—I will configure it to send a Slack notification when a Google App Engine health check log is detected.
Filtering logs in the Cloud Logging screen
Click through the Log fields pane to narrow down your conditions and identify the logs you want to detect. Ultimately, I narrowed it down with the following query:
resource.type="gae_app"
severity=INFO
log_name="projects/market-project/logs/appengine.googleapis.com%2Fnginx.health_check"
resource.labels.module_id="default"
With this state, click on Create alert.

This will take you to the alert creation screen, so proceed with the input. I set it up as follows this time:

- Alert name: Health check received
- Define log entries to alert on: This is the query condition for triggering the alert. Since the query I entered above should already be pre-filled, click "Next" if there are no issues.
- Notification frequency: I believe this is the polling interval. I set it to 5 minutes because I want to receive it immediately.
- Notification Channels: You set the destination here, but it should be empty at first. Please open "Manage notification channels" in a separate tab.
Creating a notification destination (Slack integration)
A screen like the following will open.

This time, I will install the app into a Slack workspace for notifications. Click Add New under Slack. From here on, the operations are in Slack. When you log in to your workspace, you will be asked if it is okay to install "Google Cloud Monitoring," so click OK. Return to the Google Cloud screen; you will be on the channel configuration screen, so enter the notification destination.

Perform a TEST CONNECTION to trigger a test notification, and verify it.

With this, the integration with Slack is complete.
Configuring the notification destination
Now that you have created the notification destination, link it to the alert policy you are in the middle of creating. You should have stopped at 4. Who should be notified? (Optional), so specify the notification channel you created there. After that, click SAVE.

This completes the configuration.
Verifying the notification
When a log that matches the alert policy is output, a notification will be sent to Slack.

Conclusion
I was able to detect Cloud Logging content and send notifications without having to set up Cloud Pub/Sub or Cloud Functions. The ways to handle notifications tend to increase, making maintenance difficult, so it is nice to be able to clearly separate roles: the application side handles log output, and cloud-side services handle detection and notification.
Discussion