functions-framework-go icon indicating copy to clipboard operation
functions-framework-go copied to clipboard

Support normal request logging

Open dinvlad opened this issue 5 years ago • 10 comments

Hi Team,

Would it be possible to enable optional logging of all requests? For HTTP functions, it'd be helpful to see response status and some basic metrics like request latency, while developing locally.

Thanks

dinvlad avatar Sep 26 '20 02:09 dinvlad

Sorry, can you be more specific? What is an expected command/feature that doesn't work right now?

Within your function, you can log on all requests as normal.

log.Print("foobar")

If you're running a compiled Go binary, you can just use normal bash tools like time ./my-function to see request latency.

grant avatar Oct 07 '20 21:10 grant

Hi @grant - I'm referring to automatic logging of all requests by this library, as opposed to only the errors. For sure, we could add logging in our own code, but I was curious if this could be done out-of-the-box, similarly to how for example each request gets logged in Nginx or similar proxies. Does that make sense? Thanks

dinvlad avatar Oct 07 '20 22:10 dinvlad

Oh, I don't think we have that feature, logging all requests, in the frameworks.

We could add a sample that does that.

We want to be careful of not logging PII, as it's very easy to create a vulnerable system if you just all requests. Was just talking to @grayside about this.

grant avatar Oct 07 '20 22:10 grant

Request logging is already handled when the framework is deployed to GCF, sounds like this ask is specifically to add some minimal request logging for local development. I think that makes sense.

Something along the lines of a simplified nginx access log, or replicating the HTTPRequest object from the GCF request log.

grayside avatar Oct 07 '20 23:10 grayside

Makes sense, thanks for clarifying it! I was thinking to add only general logging however, like the response status and possibly request latency, possibly only for local development indeed. Exactly how it's done in Nginx!

dinvlad avatar Oct 07 '20 23:10 dinvlad

Basically, something to indicate that a request was done and its status/run time.

dinvlad avatar Oct 07 '20 23:10 dinvlad

A pull request / forked example would mean a lot in terms of understanding the change. If this feature isn't added to the framework, you can always deploy your function to Cloud Run.

grant avatar Oct 07 '20 23:10 grant

If we exposed the middleware that takes the HTTP request and calls the user's function, users could register the handlers however they want. Part of that includes adding additional logging as desired.

There are a lot of different ways to do logging. I don't think we should pick a way to do it in this project.

Note: this also came up with #25.

tbpg avatar Oct 12 '20 15:10 tbpg

I think exposing an ability to add middlewares is a good way to facilitate this use case, leveraging the existing ecosystem of middlewares examples and libraries, and inviting developers to create reusable utilities.

The challenge might be in helping differentiate by environment: we don't want users to add request logging in GCF, do they'd want to make this change in main() instead of in their function file.

grayside avatar Oct 12 '20 16:10 grayside

Agreed, I think it'd be nice to expose a common way to add middlewares in main(), which would make the framework extensible to cover any needs of development for any runtime.

dinvlad avatar Oct 12 '20 20:10 dinvlad