GoogleCloudPlatform / functions-framework-nodejs

FaaS (Function as a service) framework for writing portable Node.js functions
Apache License 2.0
1.29k stars 158 forks source link

Functions Framework v3.4.0 breaks logging in Firebase projects #617

Closed lox closed 1 month ago

lox commented 1 month ago

See https://github.com/firebase/firebase-functions/issues/1580

Full reproduction at https://github.com/patientnotes/gcp-case-52054407

jrmfg commented 1 month ago

Thanks - fixed in #620 - we still need to do a release so I'll leave this open for now.

jrmfg commented 1 month ago

Tested, this works great. Going to cut the release.

jrmfg commented 1 month ago

Fixed in 3.4.1.

jesus-velasco-inditex commented 1 month ago

Good morning,

We are sill experiencing this issue in cloud functions framework (NODE) version 3.4.1. We are not using firebase, only GCP with the code below

We leave here the example that we are testing: 1 2 3

const functions = require('@google-cloud/functions-framework');

functions.http('main', (req, res) => {
  console.warn("I should be a warning in the logs")
  res.send(`Hello ${req.query.name || req.body.name || 'World'}!`);
});

Any suggestion/update?

Best regards.

jrmfg commented 1 month ago

To handle log levels correctly in log explorer, use structured logging (or the firebase logging library); all the nodejs console logging facilities are just writing a colored message to either stdout or stderr, so there's little we can do to tag logs with these APIs with the correct log level

We've never handled console.warn in cloud logging/structured logs. Before 3.4.0, this showed as a log at "default" level. After 3.4.0, this shows as an error, which is not really correct either. Neither have ever shown console.warn as a warning.

We could consider changing this to show default log levels for unstructured logs as before 3.4.0 if this is breaking you. Would you prefer that?

jrmfg commented 1 month ago

We could also try to be clever and use the ANSI color codes at the start of the string to try to figure out if it's a warn or error, and add structured logging accordingly. might be cool, but also isn't backwards compatible.

jesus-velasco-inditex commented 1 month ago

First of all, thanks @jrmfg for your answer, we will change to structured logs if it is not supported warn in unstructured logs .

Well, we change to structured logging using Google Library, but is there a way to put a message and extra information without put the message in a sublevel as a simple string do it?

5 4

jrmfg commented 1 month ago

but is there a way to put a message and extra information without put the message in a sublevel as a simple string do it?

I'm not sure what you mean - the code you provided looks good, what problem are you having with it?

jrmfg commented 1 month ago

rolled back the stderr change in #625; it should land in 3.4.2.