firebase-functions icon indicating copy to clipboard operation
firebase-functions copied to clipboard

[logger]: express deprecated req.host: Use req.hostname instead

Open jdcoldsmith opened this issue 1 year ago • 3 comments

Related issues

[REQUIRED] Version info

4.9.0 (I realize that this isn't the latest version but I have compared the code and couldn't find anything related to logger)

node:

20

firebase-functions:

Hello, I recently experienced this error in a 2nd gen Node.js 20 firebase function and I wanted to pass it along to you fine folks. image This seems to be an issue with the logger package.

jdcoldsmith avatar May 21 '24 12:05 jdcoldsmith

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

google-oss-bot avatar May 21 '24 12:05 google-oss-bot

Hey @jdcoldsmith. Could you give me a code sample that causes this log?

exaby73 avatar Jun 17 '24 13:06 exaby73

It seems to happen for me whenever I call log within an onRequest firebase function. This is how I import log: const { log } = require('firebase-functions/logger');

jdcoldsmith avatar Jun 17 '24 15:06 jdcoldsmith

Hi @jdcoldsmith. We reviewed our source code and don't see any direct reference to the req.host object.

I'm wondering what object you are passing to the logger module. The logger module will iterate through all keys in an object that is passed while serializing the object, and maybe the req.host is being used within that code.

taeold avatar Jul 18 '24 16:07 taeold

Ahh ok I think I see what could be happening. Whenever I get an error in my function I am passing the entire express request to the log function of logger (e.g. log('Error', { request })). Is it possible that logger is throwing this warning from that?

jdcoldsmith avatar Jul 22 '24 13:07 jdcoldsmith

Hey @jdcoldsmith. Yeah this is entirely possible since the logger iterates over the entire object to format it correctly before actually logging it. I'd recommend you log only properties you're interested in, like the hostname, any query params, etc. instead of logging the entire request object which may be logging a lot of unnecessary information polluting your logs.

But since this is not an issue with the logger itself, I feel safe to close this issue. Thank you!

exaby73 avatar Jul 23 '24 06:07 exaby73

Ok that makes sense! Thank you!

jdcoldsmith avatar Jul 23 '24 12:07 jdcoldsmith

I fixed it by running npm update.

nilsreichardt avatar Oct 18 '24 10:10 nilsreichardt