Use Stackdriver Debug with Google Cloud Functions

允我心安 提交于 2019-12-11 17:04:24

问题


There is a similar question regarding Debugging Firebase Cloud Functions using Stackdriver.

The answer there, however, doesn't seem to help at all with getting Stackdriver Debug to work with my normal Cloud Function (not Firebase). I've tried sourcing the code from Github and a Cloud Source Repository - but that doesn't seem to work. Both times I get in the side bar:

This project does not include any running applications.

The documentation about debugging Cloud Functions seems to say nothing about using Stackdriver Debug. Is there any way to use Stackdriver Debug with Cloud Functions?


回答1:


I ended up finding the solution from this video: https://youtu.be/BybYim0HRmY?t=21m42s

Quite simply you add require("@google/cloud-debug") to the top of your index.js (or whatever file your function is in). Then add @google/cloud-debug as a dependency in your package.json.

You can then manually import the code into Stackdriver Debug and you're good to go.




回答2:


Cloud Debugger does not support Cloud Functions just yet.

Although it might seem to work by adding require("@google/cloud-debug"), it is not reliable as you would like it to be. This is because the Function might be shutdown before the debugger code is able to initialize or able to report the result back to the debugger server.

The Cloud Function team at google are working to enable the debugger in a reliable way.




回答3:


Looks like the cloud-debug package is obsolete and has been renamed to @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`



回答4:


The Stackdriver Debugger npm package has been renamed to @google-cloud/debug-agent and you need to use the newly introduced isReady function to make it work reliably on Google Cloud Functions.

Check out the solution here: https://medium.com/@thoughtspeed7/stackdriver-debugger-on-google-cloud-functions-d49a6ee5f12c



来源:https://stackoverflow.com/questions/45868544/use-stackdriver-debug-with-google-cloud-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!