跟踪 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 错误。