【问题标题】:get GCP cloud function logs label.executionid获取 GCP 云函数日志 label.executionid
【发布时间】:2021-04-22 11:48:50
【问题描述】:

我想获取 GCP 提供给云函数的执行 ID,以便将其存储在数据库中。

这就是我想要的 =>

let currId = log.label.execution_id

为了做到这一点,我正在获取日志,这要归功于这个功能(在我的 cloudFunctions 中):

const logging = new Logging();
console.log(`executed ${eId}`)
printEntryMetadata(eId, sId);

async function printEntryMetadata(eId, sId) {
    const options = {
        filter: `textPayload = "executed ${eId}"`
    };
    
    const [entries] = await logging.getEntries(options);
    console.log('Logs:');
    console.log(`textPayload = "executed ${eId}"`)
    console.log(JSON.stringify(entries))
    // const metadata = entries[0].metadata
    console.log(`${metadata.labels.execution_id}`)
}

但是JSON.stringify(entries) 返回一个空数组。当我手动使用过滤器时,它正在工作...... 云功能无法获取自己的日志吗?

【问题讨论】:

  • 你能分享更多细节吗?比如你现在已经在使用什么代码来获取这些日志?
  • 抱歉这个迟到的回复......顺便说一句我已经编辑了这个问题:)

标签: node.js google-cloud-platform


【解决方案1】:

这就是我所做的:

exports.LogMetadata = async(executionId, scopeId, ProjectID, Logging) => {
    const logging = new Logging({ProjectID});
    const options = {
        filter: `textPayload = "executed ${executionId}.${scopeId}"`
    };
    
    const [entries] = await logging.getEntries(options);
    console.log(JSON.stringify(entries))
    try {
        const metadata = entries[0].metadata
        console.log(`${metadata.labels.execution_id}`)
    } catch (error) {
        console.log("can't find the log, cause' it's the first function executed...")
    }

}

唯一不起作用的是我无法获取第一个执行函数的第一个日志。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-06
    • 2023-03-12
    • 1970-01-01
    • 2021-06-07
    • 1970-01-01
    • 1970-01-01
    • 2021-09-12
    • 1970-01-01
    相关资源
    最近更新 更多