将 Stackdriver Debug 与 Google Cloud Functions 结合使用

Use Stackdriver Debug with Google Cloud Functions

关于 Debugging Firebase Cloud Functions using Stackdriver 也有类似的问题。

然而,那里的答案似乎对让 Stackdriver Debug 与我的普通 Cloud Function(不是 Firebase)一起工作没有任何帮助。我试过从 Github 和 Cloud Source Repository 获取代码 - 但这似乎不起作用。两次我都进入侧边栏:

This project does not include any running applications.

有关调试 Cloud Functions 的文档似乎只字不提使用 Stackdriver Debug。有什么方法可以将 Stackdriver Debug 与 Cloud Functions 结合使用吗?

我最终从这个视频中找到了解决方案:https://youtu.be/BybYim0HRmY?t=21m42s

很简单,您将 require("@google/cloud-debug") 添加到 index.js 的顶部(或您的函数所在的任何文件)。然后在 package.json.

中添加 @google/cloud-debug 作为依赖项

然后您可以手动将代码导入 Stackdriver Debug,一切顺利。

Cloud Debugger 目前还不支持 Cloud Functions。

尽管添加 require("@google/cloud-debug") 似乎可以工作,但它并不像您希望的那样可靠。这是因为函数可能在调试器代码能够初始化或能够将结果报告回调试器服务器之前关闭。

google 的 Cloud Function 团队正在努力以可靠的方式启用调试器。

看起来云调试包已过时并已重命名为@google-cloud/debug-agent:

    yarn add @google/cloud-debug
    yarn add v0.23.4
    [1/4]   Resolving packages...
    warning @google/cloud-debug@0.9.3: This module has been renamed to @google-cloud/debug-agent, please use that instead.
    warning @google/cloud-debug > google-auth-library > request > node-uuid@1.4.8: Use uuid module instead`

Stackdriver Debugger npm 包已重命名为 @google-cloud/debug-agent,您需要使用新引入的 isReady 函数才能使其在 Google Cloud Functions 上可靠运行。

在此处查看解决方案:https://medium.com/@thoughtspeed7/stackdriver-debugger-on-google-cloud-functions-d49a6ee5f12c