When a published Google Chat apps returns an error, the Chat interface surfaces a generic message saying "Something went wrong." or "Unable to process your request." Sometimes the Chat UI doesn't display any error message, but the Chat app produces an unexpected result. To debug a Chat app, view its logs in Google Cloud Logs Explorer.
This guide describes how to query Chat app error logs in Google Cloud Logs Explorer, so you can:
- Learn if users encounter errors.
- See how often errors occur, and which are most frequent.
- Read descriptive error messages and log data that help you fix the errors.
Prerequisites
To query Chat app error logs, you need:
- A Google Workspace account with access to Google Chat.
- A Chat app. To build a Chat app, follow this quickstart.
Set up the environment
Before querying Chat app error logs, you must enable the Cloud Logging API in the Chat app's Google Cloud project.
In the Google Cloud console, enable Cloud Logging API.
Enable error logging
Enable error logging and when a Chat app throws an error, it logs it to Cloud logging.
In the Google Cloud console, go to the Chat API configuration page.
Under Functionality, select Log errors to Cloud Logging.
Click Save.
Now, whenever the Chat app throws an error, the error gets logged to Cloud Logging.
Turn off error logging
Because Cloud Logging incurs a cost, you may wish to turn off error logging.
In the Google Cloud console, go to the Chat API configuration page.
Under Functionality, deselect Log errors to Cloud Logging.
Click Save.
Now, whenever the Chat app throws an error, the error doesn't get logged to Cloud Logging. You can continue to query past error logs using Logs Explorer.
Query error logs
To get logs for a Chat app:
In the Google Cloud console, go to the Log Explorer.
If necessary, to show the query builder, turn on Show query.
For Chat app error logs, enter the following query:
severity=ERROR resource.type="chat.googleapis.com/Project"
To see recent errors, click Run query. Or, to see errors as they occur, click Stream logs. Chat app error logs appear in the "Query results" pane.
To learn more about Google Cloud Logs Explorer and writing queries, see:
Read an error message from a log
After querying an error log, you can view individual logs which consist of a JSON payload describing the log. For Chat app errors, the JSON includes the error message at jsonPayload.error.message
. For example, in the following sample log, the error message says that an Apps Script function failed to execute:
JSON
{
"insertId": "INSERT_ID",
"jsonPayload": {
"@type": "type.googleapis.com/google.chat.logging.v1.ChatAppLogEntry",
"error": {
"code": 9,
"message": "An Apps Script function failed to execute. To review AppsScript error logs, see \"Logging\" (https://developers.google.com/apps-script/guides/logging)."
},
"deployment": "DEPLOYMENT_ID"
},
"resource": {
"type": "chat.googleapis.com/Project",
"labels": {
"project_id": "PROJECT_ID"
}
},
"timestamp": "2022-12-06T05:24:18.697255Z",
"severity": "ERROR",
"logName": "projects/PROJECT_ID/logs/chat.googleapis.com%2Ferrors",
"receiveTimestamp": "2022-12-06T05:24:19.207936968Z"
}
Considerations
As you work with Chat app error logs in Google Cloud Logs Explorer, take note of these considerations:
For Chat app, Logs Explorer currently includes logs with the following severities which help troubleshoot a malfunctioning app:
ERROR
Other log types are not recorded, however, logs of related services can also help debug a Chat app. For example, if a Chat app is deployed using Google Cloud Functions, then it's a best practice to check Logs Explorer for Cloud Functions logs too.
Error messages are always written in English.
Cloud Logging incurs a cost. For further information on Cloud Logging pricing, refer to Google Cloud's operations suite pricing.