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

ESM loader has multiple issues in v11 #1821

Closed
antmarot opened this issue Oct 17, 2023 · 3 comments · Fixed by #1894
Closed

ESM loader has multiple issues in v11 #1821

antmarot opened this issue Oct 17, 2023 · 3 comments · Fixed by #1894
Assignees

Comments

@antmarot
Copy link

Description

Using --loader newrelic/esm-loader.mjs in v11 leads to several issues that did not exist in v10:

  • Some packages are not properly instrumented. From my experiments, ioredis, winston, amqplib, aws-sdk, prisma are not properly instrumented (eg. no data posted), while fastify works (I'm getting Fastify//* transactions).
  • It may depends on the "style" of the import statement. For instance, as detailed below, winston is properly instrumented in v11 as long as it's imported like this import winston from "winston" and not like this import * as winston from "winston". v10 handles both cases properly.
  • v11 sometimes crashes silently. I experience this when importing puppeteer for instance. Potentially due to Loader fails when circular dependencies exist within an application nodejs/import-in-the-middle#32

Expected Behavior

No regression in ESM loader in v11 wrt v10.

Steps to Reproduce

This only illustrates the import style issue as this is the only one I could pinpoint.

// v10/package.json
{
  "name": "v10",
  "type": "module",
  "dependencies": {
    "newrelic": "10.6.2",
    "winston": "3.11.0"
  }
}

// v10/import-all-as.js
import * as winston from 'winston';
const logger = winston.createLogger({ transports: new winston.transports.Console() });
logger.warn('V10: import * as');
await new Promise((resolve) => { setTimeout(() => resolve(), 5000); });

// v10/import-default.js
import winston from 'winston';
const logger = winston.createLogger({ transports: new winston.transports.Console() });
logger.warn('V10: default import');
await new Promise((resolve) => { setTimeout(() => resolve(), 5000); });

// v11/package.json
{
  "name": "v11",
  "type": "module",
  "dependencies": {
    "newrelic": "11.2.1",
    "winston": "3.11.0"
  }
}

// v11/import-all-as.js
import * as winston from 'winston';
const logger = winston.createLogger({ transports: new winston.transports.Console() });
logger.warn('V11: import * as');
await new Promise((resolve) => { setTimeout(() => resolve(), 5000); });

// v11/import-default.js
import winston from 'winston';
const logger = winston.createLogger({ transports: new winston.transports.Console() });
logger.warn('V11: default import');
await new Promise((resolve) => { setTimeout(() => resolve(), 5000); });
cd v10
NEW_RELIC_LICENSE_KEY=x NEW_RELIC_APP_NAME=x node --loader newrelic/esm-loader.mjs -r newrelic import-all-as.js
NEW_RELIC_LICENSE_KEY=x NEW_RELIC_APP_NAME=x node --loader newrelic/esm-loader.mjs -r newrelic import-default.js
cd ../v11
NEW_RELIC_LICENSE_KEY=x NEW_RELIC_APP_NAME=x node --loader newrelic/esm-loader.mjs -r newrelic import-all-as.js
NEW_RELIC_LICENSE_KEY=x NEW_RELIC_APP_NAME=x node --loader newrelic/esm-loader.mjs -r newrelic import-default.js

Results in dashboard:
newrelic-import-v11
No V11: import * as log entry.

Your Environment

  • Node 18
  • MacOS
@workato-integration
Copy link

@bizob2828
Copy link
Member

bizob2828 commented Oct 17, 2023

Sorry you're having trouble @antmarot. I have confirmed the bug around import * as vs import name. I'll dig more into the import-in-the-middle code as it doesn't appear to be the interaction in our code. It's just not wrapping the right code when import * as

@jsumners-nr
Copy link
Contributor

Thank you for the clear test cases. They were very helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
3 participants