Being More Aware Of Application Errors by Connecting Cloud Monitoring to Slack Channel

Hello Everyone,

How often do you check the server logs for errors? How long has the error been left? Instead of doing that, Let's create an error detector! 🚀

In my current company, I created a slack channel named error-detector-** . That slack channel is used for receiving an error message from cloud monitoring when there’s a server error. We can do a “query” for an error, so we can determine which error should send to the channel.

Creating an Alert in Cloud Monitoring

We need to define which error we want to send to the slack message by accessing logs explorer.

I only want to send a message to the slack channel when there’s an error in my service in the cloud run. So, This is a filter that I use.

resource.type="cloud_run_revision"
resource.labels.service_name="MY_CLOUD_RUN_SERVICE_NAME"
severity=(WARNING OR ERROR OR CRITICAL OR ALERT OR EMERGENCY)

Now, click the button “Create alert” with that query

This is my configuration for the alert. I wanna a notification per 10 minutes and the Incident autoclose duration is 7 days. Don’t submit and close this page, we wanna connect this alert with the notification channel

Let’s click the button “Manage Notification Channel”, it will open a new tab.
There are many notification channels there. I use “Slack” and click the button “ADD NEW”.

Creating a Notification Channel

My cloud account is already connected to Google Cloud Monitoring, so I just need to allow it. But for you, just follow the steps.

After success installing Google Cloud Monitoring in your slack app and you’ll be redirected to the previous page with a modal.

Enter your slack channel name and display the name, click the button “SAVE”.

Integrate Slack Channel with the Google Cloud Monitoring App

To verify Google Cloud Monitoring installation, you can see it on the “Installed Apps” page.

Now, open your slack and add the “Google Cloud Monitoring App” in the Apps section.

Integrate the Alert with Notification Channel

back to the previous page “Create Alert Form”. Click the refresh button, you will see the channel that we created before like image below. Submit the form!

Now, when there’s an error. You will receive a message to your slack channel like this

Thank you for reading this article! 🎉
Reach me: https://www.linkedin.com/in/didikmulyadi/

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Didik Mulyadi

Didik Mulyadi

Sharing about problems and solution based on real experiences (Backend, Frontend, Cloud Platform) reach me https://www.linkedin.com/in/didikmulyadi/