活动日志记录
本文档介绍了如何使用 Cloud Logging 对 Identity Platform 进行活动日志记录。
启用活动日志记录
活动日志记录默认处于停用状态。您可以通过 Google Cloud 控制台或使用 REST API 启用活动日志记录:
控制台
- 前往 Google Cloud 控制台中的设置页面。 
 前往“设置”
- 在用户活动日志下,选择启用。 
- 点击保存。 
REST
curl -d "{'monitoring':{'requestLogging':{'enabled':true}}}" \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "x-goog-user-project: PROJECT_ID" \ -X PATCH -H 'Content-Type: application/json' \ https://identitytoolkit.googleapis.com/admin/v2/projects/PROJECT_ID/config?updateMask=monitoring.requestLogging.enabled
请将 PROJECT_ID 替换为您的 Google Cloud 项目 ID。
启用活动日志记录可能会影响您的结算。如需了解详情,请参阅 Google Cloud Observability 价格。
为租户项目启用活动日志记录
默认情况下,租户项目的活动日志记录处于停用状态。您可以使用 REST API 为租户项目启用活动日志记录,方法是执行以下命令:
curl -d "{'monitoring':{'requestLogging':{'enabled':true}}}" \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "x-goog-user-project: PROJECT_ID \ -X PATCH -H 'Content-Type: application/json' \ https://identitytoolkit.googleapis.com/v2/projects/PROJECT_ID/tenants/TENANT_ID?updateMask=monitoring.requestLogging.enabled
替换以下内容:
- PROJECT_ID:您的 Google Cloud 项目 ID。
- TENANT_ID:Identity Platform 租户的 ID。
启用活动日志记录可能会影响您的结算。如需了解详情,请参阅 Google Cloud Observability 的价格。
查看活动日志
启用 Logging 后,系统会为每个用户请求生成日志条目。每个日志条目都包含以下字段:
| 字段 | 说明 | 
|---|---|
| logName | projects/PROJECT_ID/logs/identitytoolkit.googleapis.com/requests | 
| resource | identitytoolkit_project or identitytoolkit_tenant | 
| serviceName | identitytoolkit.googleapis.com | 
| protoPayload | 记录的请求或响应。 | 
您可以使用日志浏览器查看项目或租户的活动日志。要查看日志,请执行以下操作:
- 在 Google Cloud 控制台中,前往 Logs Explorer 页面。 
- 从资源列表中选择 Identity Toolkit 项目或 Identity Toolkit 租户。如果您使用的是多租户,则可以显示所有租户,或过滤到特定租户。 
记录的操作
下表列出了可以生成活动日志的 API 操作:
| 服务 | 方法 | 
|---|---|
| google.cloud.identitytoolkit.v1.AccountManagementService | DeleteAccount | 
| GetAccountInfo | |
| GetOobCode | |
| ResetPassword | |
| SetAccountInfo | |
| google.cloud.identitytoolkit.v1.AuthenticationService | CreateAuthUri | 
| GetRecaptchaParam | |
| SendVerificationCode | |
| SignInWithCustomToken | |
| SignInWithEmailLink | |
| SignInWithGameCenter | |
| SignInWithIdp | |
| SignInWithPassword | |
| SignInWithPhoneNumber | |
| SignUp | |
| VerifyIosClient | |
| google.cloud.identitytoolkit.v1.ProjectConfigService | GetProjectConfig | 
排除操作
Logging 为您提供了停用日志提取或排除您不需要的日志条目的工具。如需详细了解如何排除某些日志,请参阅日志排除。
以下示例展示了如何为只读 GetAccountInfo() 和 GetProjectConfig() 方法排除日志:
resource.type="identitytoolkit_project"
(
 jsonPayload.methodName="google.cloud.identitytoolkit.v1.AccountManagementService.GetAccountInfo"
 OR
 jsonPayload.methodName="google.cloud.identitytoolkit.v1.ProjectConfigService.GetProjectConfig"
)