You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase云函数从Gen1迁移到Gen2后日志过滤及日志差异咨询

Firebase Cloud Functions Gen1 转 Gen2 日志过滤与差异问题

1. 如何按函数名进行过滤?

Gen2 函数的日志资源结构和 Gen1 不同,你可以通过以下方式按函数名过滤:

  • 通过资源标签过滤:Gen2 函数日志的资源类型为 cloudfunctions.googleapis.com/CloudFunction,函数名字段对应 resource.labels.function,过滤语句示例:
    resource.type="cloudfunctions.googleapis.com/CloudFunction"
    AND resource.labels.function="你的函数名称"
    
  • 通过自动注入标签过滤:Gen2 会自动为日志添加 labels."firebase-function" 标签,值为你的函数名,过滤语句示例:
    labels."firebase-function"="你的函数名称"
    

另外你代码中自定义的 group: "user_profile" 标签也可以用来批量过滤同组函数:

labels.group="user_profile"

2. 是否有文档说明 Gen1 与 Gen2 在日志方面的差异?

官方文档明确了 Gen2 基于 Cloud Functions v2 架构,日志的资源模型与 Gen1 存在核心差异:

  • 资源类型:Gen1 为 cloud_function,Gen2 调整为 cloudfunctions.googleapis.com/CloudFunction
  • 函数名字段:Gen1 日志中是 resource.labels.function_name,Gen2 改为 resource.labels.function
  • 额外标签:Gen2 会自动注入 labels."firebase-function" 标签,方便快速关联函数

你使用的函数配置代码

import {CallableOptions, onCall} from "firebase-functions/v2/https";
import * as logger from "firebase-functions/logger";

const options: CallableOptions = {
  labels: {
    group: "user_profile"
  },
  timeoutSeconds: 2,
  memory: "128MiB",
  minInstances: 0,
  maxInstances: 2,
  // enforceAppCheck: true,
};

onCall(options, async (req) => {
 logger.info("Example of logger");
}

内容的提问来源于stack exchange,提问作者angelcervera

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 10:51:11