是否有方法为Cloud Run服务自动生成的日志添加自定义属性?
const app = express();
app.use((req: any, res, next) => {
const myCustomHeader = req.get('x-my-custom-header');
// TODO: Add my custom header to Cloud Run automatic logs
next();
});
我想将myCustomHeader
添加到Cloud Logging输出(例如:httpRequest
对象:
{
httpRequest: {
myCustomHeader: "my custom value here",
… // Default attributes set by Cloud Run
},
insertId: "5c82b3d1000ece0000000000",
labels: {
instanceId: "someid",
mylabel: "mylabelvalue",
mysecondlabel: "mysecondlabelvalue",
},
logName: "projects/my-project/logs/run.googleapis.com%2Frequests",
receiveTimestamp: "2019-03-08T18:26:25.981686167Z",
resource: {
labels: {
configuration_name: "myservice",
location: "us-central1",
project_id: "my-project",
revision_name: "myservice-00002",
service_name: "myservice",
}
type: "cloud_run_revision",
},
severity: "INFO",
timestamp: "2019-03-08T18:26:25.970397Z",
}
1条答案
按热度按时间vcirk6k61#
根据本官方文件
当您从服务或作业写入日志时,只要日志被写入以下任何位置,Cloud Logging就会自动拾取日志:
大多数开发人员都希望使用标准输出和标准错误来编写日志。
因此,如果您想向日志添加一些自定义属性,请按照生成日志的文档中给出的步骤进行操作。