我正在使用 Firebase 函数和 Stackdriver。
Stackdriver 与 Firebase 功能集成得很好,因此我可以使用该console.error命令轻松记录错误。但是,我不仅想记录错误对象,还想记录查询参数。如果我可以在同一日志行中记录错误对象和查询参数,则可以轻松对它们进行分组和导出。
有没有一种简单的方法可以将信息添加到 Stackdriver 上的错误日志中,如下所示?
console.error(new Error('Invalid query'), req.query)
Run Code Online (Sandbox Code Playgroud)
谢谢。
- - 编辑
我尝试了以下代码。这可以向日志条目添加一个查询参数,但不幸的是 Stackdriver 将所有错误放在一组中,如下面的屏幕截图所示。即使每个错误的类型不同并且发生在不同的文件中,所有错误也会分组在一起。我希望 Stackdriver Error Reporting 像往常一样按错误类型或堆栈跟踪对错误进行分组。
索引.js
const functions = require('firebase-functions')
const raiseReferenceError = require('./raiseReferenceError')
const raiseSyntaxError = require('./raiseSyntaxError')
const raiseTypeError = require('./raiseTypeError')
exports.stackdriverErrorLogging = functions.https.onRequest((req, res) => {
try {
switch (Math.round(Math.random() * 2)) {
case 0:
raiseReferenceError()
break
case 1:
raiseSyntaxError()
break
default:
raiseTypeError()
break
}
} catch (error) {
console.error({
error: error,
method: req.method,
query: …Run Code Online (Sandbox Code Playgroud) node.js firebase google-cloud-functions google-cloud-stackdriver google-cloud-error-reporting
到目前为止,我一直在使用 Firebase 函数。这次,我想在同一个项目中使用 Firebase Functions 和 Cloud Run。有没有一种在 Firebase Functions 和 Cloud Run 之间共享一些代码的好方法?仅通过创建符号链接就可以工作吗?或者,我需要创建私有的 npm 包吗?
我的开发环境是 Windows 10,节点 8。我正在使用 Firebase-tools 来部署 Firebase 函数,并打算使用 gcloud 命令来部署 Cloud Run。
- - 编辑
我研究了如何将私有 npm 包与 Google Cloud Source Repositories 结合使用。这个小项目看起来有点麻烦。然后我找到了有用的信息。
本地 npm 依赖项在 docker build 中“不包含 package.json 文件”,但使用 npm start 运行良好/sf/answers/4085825341/
我在下面尝试了相同的方法,它似乎工作正常。
--- 编辑 2
项目文件夹结构:
project/ ................... <- specify project root when `docker build`
?? .dockerignore ...........
?? containers/ .............
? ?? package.json ......... <- gather docker commands here …Run Code Online (Sandbox Code Playgroud) node.js firebase docker google-cloud-functions google-cloud-run