追蹤 gRPC 問題
事前準備
請務必先初始化並啟用寫入權限,再寫入記錄檔。在下列範例中,記錄檔名為 /var/log/grpc.log:
touch /var/log/grpc.logchmod 666 /var/log/grpc.log
如果遇到檔案權限問題,可能需要在先前的指令前加上 sudo。
記錄到檔案
如要將 gRPC 記錄儲存至檔案,請在 php.ini 檔案中新增下列程式碼:
grpc.grpc_verbosity=debug
grpc.grpc_trace=all,-timer_check
grpc.log_filename=/var/log/grpc.log
如要改為將記錄寫入 stderr,請從上一個範例中排除最後一行。如要進一步瞭解其他選項,請參閱 gRPC 環境變數。
錯誤詳細資料
Google Cloud 服務會遵循 AIP-193 指南傳回錯誤。Google Cloud 服務會使用一組標準錯誤酬載,您可以在 google.rpc.error_details.proto 中找到這些酬載。這些詳細資料可涵蓋大部分常見的 API 錯誤,例如配額錯誤和無效參數。
PHP 用戶端程式庫發出的 API 錯誤包含 message、code、status 和 details 欄位。
在 details 欄位中,其他 google.rpc.ErrorInfo 資料會顯示在 reason、domain 和 metadata 欄位中。如果您在啟用 Translate API 前,使用雲端專案呼叫 Translation 程式庫,可能會出現下列錯誤範例:
Google\ApiCore\ApiException: {
"reason": "SERVICE_DISABLED",
"domain": "googleapis.com",
"errorInfoMetadata": {
"consumer": "projects\PROJECT_ID",
"service": "translate.googleapis.com"
},
"message": "Cloud Translation API has not been used in project PROJECT_ID before or it is disabled. Enable it by visiting https:\/\/console.developers.google.com\/apis\/api\/translate.googleapis.com\/overview?project=PROJECT_ID then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
"code": 7,
"status": "PERMISSION_DENIED",
"details": [
{
"@type": "google.rpc.errorinfo-bin",
"reason": "SERVICE_DISABLED",
"domain": "googleapis.com",
"metadata": {
"consumer": "projects\PROJECT_ID",
"service": "translate.googleapis.com"
}
},
{
"@type": "google.rpc.help-bin",
"links": [
{
"description": "Google developers console API activation",
"url": "https:\/\/console.developers.google.com\/apis\/api\/translate.googleapis.com\/overview?project=PROJECT_ID"
}
]
}
]
}如要進一步瞭解 Google API 的一般錯誤模型,請參閱「Cloud API 錯誤」。