Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pino does not work with ESM loader in v11 #1802

Closed
y-a-v-a opened this issue Oct 9, 2023 · 5 comments
Closed

Pino does not work with ESM loader in v11 #1802

y-a-v-a opened this issue Oct 9, 2023 · 5 comments

Comments

@y-a-v-a
Copy link

y-a-v-a commented Oct 9, 2023

Description

In a NextJS 12.3.4 application we have a custom server along with Pino and NewRelic.

{
  "@newrelic/next": "0.5.2",
  "@types/newrelic": "9.14.0",
  "newrelic": "11.1.0",
  "pino": "8.15.7",
  "pino-pretty": "10.2.3",
  "next": "12.3.4"
}

When I start up Next with the following command, the application starts throwing errors immediately, but nothing to stdout or stderr.

NEW_RELIC_APP_NAME="DEV Storefront" NEW_RELIC_NO_CONFIG_FILE=true NEW_RELIC_ENABLED=true NEW_RELIC_LICENSE_KEY=123abc NODE_OPTIONS="--experimental-loader newrelic/esm-loader.mjs -r @newrelic/next --inspect" node ./server.js

From the inspector panel I do see the following:

Screenshot 2023-10-09 at 12 26 26

From one.newrelic.com we see continuous errors reported

                                                      at ThreadStream.write (/usr/src/app/storefront/node_modules/thread-stream/index.js:232:19)
                                                                  at Pino.write (/usr/src/app/storefront/node_modules/pino/lib/proto.js:215:10)
                                                          at Pino.LOG [as error] (/usr/src/app/storefront/node_modules/pino/lib/tools.js:62:21)
                                                                              at process.<anonymous> (/usr/src/app/storefront/server.js:101:12)
                                                                                                          /at process.emit (node:events:526:35)
                    at process.wrappedEmit [as emit] (/usr/src/app/storefront/node_modules/newrelic/lib/instrumentation/core/globals.js:54:23)
                                                                                at process.<anonymous> (node:internal/process/execution:149:25)
at process.wrappedFatalException [as _fatalException] (/usr/src/app/storefront/node_modules/newrelic/lib/instrumentation/core/globals.js:33:23)

Expected Behavior

No errors are reported, output is sent to stdout.

Troubleshooting or NR Diag results

Steps to Reproduce

Your Environment

NextJS v12.3.4 runs in a Docker container, versions of deps as mentioned above.
Also reproducible on Mac OS 13.5.2
NodeJS 18.17.1

All works as expected when using NewRelic v10.x.x (up until its latest version).

Additional context

Similar report found here: https://forum.newrelic.com/s/hubtopic/aAX8W000000PHYsWAO/newrelic-does-not-show-logs-for-nextjs-app?t=1696848988884

Upgrading @newrelic/next doesn't make a difference. Dropping pino-pretty in favor of using pino/file doesn't make a difference either.

@workato-integration
Copy link

@bizob2828
Copy link
Member

Hi @y-a-v-a sorry for your troubles. Can you provide a more concrete reproduction case?

@y-a-v-a
Copy link
Author

y-a-v-a commented Oct 9, 2023

Example repo here:
https://github.com/y-a-v-a/newrelic-pino
branch main errors
branch no-pino works like a charm ;-)

Cheers,
Vincent

@bizob2828
Copy link
Member

bizob2828 commented Oct 9, 2023

Hi @y-a-v-a this is a duplicate of #1777. It's a bug in a 3rd party package we use to instrument ESM(import-in-the-middle). I'll close this as a duplicate. For now, since you're using Node 18 I recommend staying on 10.x of newrelic until this issue can be fixed.

I also noticed you're using the ESM loader and a standalone server. If you rely on next CLI you could get rid of loader by doing NODE_OPTIONS='-r @newrelic/next' next start

@bizob2828 bizob2828 changed the title v11.x.y does not work well with Pino Pino does not work with ESM loader in v11 Oct 9, 2023
@y-a-v-a
Copy link
Author

y-a-v-a commented Oct 10, 2023

Hi @bizob2828, thanks for the feedback. Let's await the fix in the 3rd party package then.
It's a pity though that in all communication my manager reads, it is stressed to keep up by installing the latest versions of all NewRelic packages, and that it's considered a vulnerability when lagging behind... After digging into code for 1.5 days I now need to convince people to ignore these warnings and that we should settle with an older version.

#1777 is almost worth a mention in the README, or at least in the release notes, imho. We'll keep an eye on this repo!
Cheers, Vincent

@bizob2828 bizob2828 moved this to Done: Issues recently completed in Node.js Engineering Board Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

2 participants