Closed Laksh47 closed 4 years ago
in a sense this is by design. You must await the calls to log if expect them to finish running. If you don't await the call to log the log message will likely not be sent to the logging api before the function terminates. Resulting in a completely lost log message.
The question here is if we should fail silently. or fail loudly with a better error message. I haven't traced the code to determine why it fails to find the application default credential during function shutdown but this is probably a race :racing_car: i can imagine this error varies based on which async call its handling when things start to shutdown.
changing to p2 because there is a workaround.
I don't understand the workaround. logger.info
, logger.error
, and logger.debug
do not return Promises. Why would awaiting them work?
the logging instance is a nodejs writable stream. Because bunyan doesn't provide a way to end all attached streams in its exposed logger api you'll have to wrap end/finished on the logging-bunyan writable stream itself to await it. something like.
end = ()=>{
if(loggingBunyanStream.writableFinished) return;
return new Promise((res,rej)=>{
loggingBunyanStream.once('finished',res)
loggingBunyan.end();
})
}
then when you're done with the function await end();
The event emitted on closure is now 'finish', just discovered this by going through issues on Google's winston logging repo.
Issue:
Environment details
@google-cloud/logging-bunyan
version: 2.0.0Steps to reproduce
Error reported:
Sample Code: index.js
package.json
Note:
Could anyone help me with what's wrong here?
Reference issues: