winstonjs / winston-mongodb

A MongoDB transport for winston
https://github.com/winstonjs/winston-mongodb
295 stars 125 forks source link

NodeJS 20 Deprecation Warning DEP0170 #218

Open samuelexferri opened 1 year ago

samuelexferri commented 1 year ago

I'm using NodeJS 20 and this Winston MongoDB config:

const logger: CustomLevels = winston.createLogger({
    ...winstonLoggerOptions,
    transports: [
        new MongoDB({
            level: "info",
            db: dbURL,
            options: {
                serverSelectionTimeoutMS: 2147483647, // Never stop trying to reconnect
                useNewUrlParser: true,
                useUnifiedTopology: true,
            },
            collection: "logs",
            storeHost: true,
            capped: false, // Alternative to expireAfterSeconds
            tryReconnect: true,
            decolorize: true,
            expireAfterSeconds: 60 * 60 * 24 * 120, // 120 days
        }),
        new winston.transports.Console({
            level: "debug",
        }),
    ],
});

I get this warning when running: (node:40350) [DEP0170] DeprecationWarning: The URL mongodb://project-staging:password@sp-cluster0-shard-00-02.t3lku.gcp.mongodb.net:27017,sp-cluster0-shard-00-00.t3lku.gcp.mongodb.net:27017,sp-cluster0-shard-00-01.t3lku.gcp.mongodb.net:27017/project-staging?authSource=admin&replicaSet=sp-cluster0-shard-0&ssl=true is invalid. Future versions of Node.js will throw an error.

Earlier versions of NodeJS (<19) don't throw any warnings.

DABH commented 1 year ago

Open to PRs that would help address/fix this issue, if you're up for investigating a bit further as to why we're getting this error. Unsure if we need to change the URL being generated, or if we can do things differently with Node so that it doesn't complain about this URL type.

DABH commented 1 year ago

It's possible this is related to our need to do a major version upgrade of the mongodb package, see https://github.com/winstonjs/winston-mongodb/pull/223 which is currently failing. If you (or anyone else) would like to volunteer to help get that working, it would be a fantastic help and would help continue the useful life of this transport.

usaszerelem commented 1 year ago

Confirming that this is happening with increased frequency. Had this confirmed with Atlas DB support. Node version 20, all the latest NPM packages as of this writing. Below output with --trace-deprecation flag turned on.

(node:30480) [DEP0170] DeprecationWarning: The URL mongodb://user:password@ac-mrbfemw-shard-00-00.xpoqxtm.mongodb.net:27017,ac-mrbfemw-shard-00-01.xpoqxtm.mongodb.net:27017,ac-mrbfemw-shard-00-02.xpoqxtm.mongodb.net:27017/?authSource=admin&replicaSet=atlas-cu6uf5-shard-0&retryWrites=true&w=majority&ssl=true is invalid. Future versions of Node.js will throw an error. at getHostname (node:url:544:17) at Url.parse (node:url:409:14) at Object.urlParse [as parse] (node:url:166:13) at parseConnectionString (/Users/user/Projects/Node/products-api/node_modules/winston-mongodb/node_modules/mongodb/lib/core/uri_parser.js:578:9) at QueryReqWrap.callback (/Users/user/Projects/Node/products-api/node_modules/winston-mongodb/node_modules/mongodb/lib/core/uri_parser.js:127:7) at QueryReqWrap.onresolve [as oncomplete] (node:internal/dns/callback_resolver:49:10)

From Atlas DB engineers: The warning is coming from winston-mongodb which has a dependency on mongodb: ^3.6.2. The 3.x driver did make use of the deprecated API

DABH commented 1 year ago

Yeah, so like I mentioned above, I think we need someone from the community to help us get #223 working. If anyone can make that PR pass the tests, it will fix this issue for everyone going forwards. Let me know if anyone is willing to take this on - it would obviously be a huge help and greatly appreciated!

usaszerelem commented 1 year ago

Hello David, thank you for your response. I am a relatively beginner with Node, so I know enough to be dangerous but not sufficiently to help in the requested capacity. What I commit to do is that if somebody steps up to help, I will provide funding for this project.

DABH commented 1 year ago

Sponsorship would enable me to take a stab at this! :) https://github.com/sponsors/DABH But very open in the meantime if someone in the community wants to volunteer.

Sakibdevlekar commented 6 months ago

i like to give it a try to solve this issue, can you assign this task to me

DABH commented 6 months ago

Absolutely! Thanks @Sakibdevlekar for volunteering to investigate. If you happen to reproduce and fix this issue, please feel free to tag me for review in a PR! 🙏

Neitan2001 commented 5 months ago

Hello, I am facing the same issues. Is this issue resolved?

MattMinerQuotable commented 4 months ago

Hi all, not sure if this is still on people's minds, but here is a good question / answer on Stackoverflow dealing with a similar issue: https://stackoverflow.com/questions/76594556/receive-dep0170-when-connecting-mongodb-atlas-with-node-js-20-3-1

Essentially, looking at the node docs on this one (https://nodejs.org/api/deprecations.html#DEP0170), it looks as if this is based on an issue with the current mongodb implementation (as mentioned above with the bump to mongodb 6.5.0). @Sakibdevlekar were you able to resolve this?

earonesty commented 6 days ago

see: https://github.com/npm/cli/issues/6869