<!-- llms-explorer concept facts · https://llms-explorer.com/tree/new-relic-node-preload-order-and-mongodb-trace-verification-boundary/ · pack 2026-11-02 · ~1405 tokens -->

# New Relic Node preload order and MongoDB trace-verification boundary

> Source-anchored research for New Relic Node preload order and MongoDB trace-verification boundary. Run status: COMPLETED.

Parent: [New Relic Integration](https://llms-explorer.com/tree/new-relic-integration/) · 2 facets · 8 facts · page: https://llms-explorer.com/tree/new-relic-node-preload-order-and-mongodb-trace-verification-boundary/

## Problems, failure modes and limitations

- New Relic directs applications to preload the Node agent with `node -r newrelic ./dist/server.js`; when startup flags cannot be controlled, place `require('newrelic')` first in the main module, before other packages. Late loading can prevent proper instrumentation. New Relic warns that the first-line fallback causes instrumentation issues with Babel or a similar transpiler. (medium confidence) (verified as of 2026-11-02) — [source](https://docs.newrelic.com/docs/apm/agents/nodejs-agent/installation-configuration/install-nodejs-agent/) · [also](https://docs.newrelic.com/docs/apm/agents/nodejs-agent/troubleshooting/troubleshoot-your-nodejs-installation/)
- For an ESM application that uses a configuration file, New Relic requires changing its extension from `.js` to `.cjs` because the CommonJS agent reads the file with `require()`; otherwise startup can fail with `ERR_REQUIRE_ESM`. (low confidence) (verified as of 2026-11-02) — [source](https://docs.newrelic.com/docs/apm/agents/nodejs-agent/installation-configuration/es-modules/) · [also](https://raw.githubusercontent.com/newrelic/docs-website/develop/src/content/docs/apm/agents/nodejs-agent/installation-configuration/es-modules.mdx)
- New Relic documents that `newrelic.instrumentLoadedModule` is unsupported for ESM: ESM bindings cannot be assigned, preventing replacement of exports after loading. Do not plan an ESM verification procedure around retrofitting this API after imports. (low confidence) (verified as of 2026-11-02) — [source](https://docs.newrelic.com/docs/apm/agents/nodejs-agent/installation-configuration/es-modules/) · [also](https://raw.githubusercontent.com/newrelic/docs-website/develop/src/content/docs/apm/agents/nodejs-agent/installation-configuration/es-modules.mdx)
- In the MongoDB issue opened on Nov 4, 2025, the reporter said the application continued working while instrumentation failed and MongoDB metrics were not collected; the reported error was `TypeError: Cannot read properties of undefined (reading 'prototype')`. A maintainer requested runnable reproduction code on Jan 23, 2026, then closed the issue on Mar 3, 2026 and invited reopening with a reproduction. These are attributed observations, and that closure does not establish a released instrumentation fix or a general compatibility rule. (low confidence) — [source](https://github.com/newrelic/node-newrelic/issues/3488)

## Facts and statements

- For ESM applications, New Relic requires the ESM loader together with the agent: `node --import newrelic/esm-loader.mjs -r newrelic ./dist/server.js`. Loading the agent alone does not fulfill this documented ESM bootstrap requirement. The ESM setup page labels this instrumentation experimental and warns that breaking changes can occur while its loader dependency is experimental. (medium confidence) (verified as of 2026-11-02) — [source](https://docs.newrelic.com/docs/apm/agents/nodejs-agent/installation-configuration/install-nodejs-agent/) · [also](https://docs.newrelic.com/docs/apm/agents/nodejs-agent/installation-configuration/es-modules/) · [also](https://docs.newrelic.com/docs/apm/agents/nodejs-agent/troubleshooting/troubleshoot-your-nodejs-installation/) · [also](https://raw.githubusercontent.com/newrelic/docs-website/develop/src/content/docs/apm/agents/nodejs-agent/installation-configuration/es-modules.mdx)
- The pinned Node release 22.14.0 CLI documents that modules preloaded with --require run before modules preloaded with --import. Repeated import preloads execute sequentially in order, beginning with those supplied in NODE_OPTIONS. The option order shown in New Relic examples does not reverse that runtime ordering. (medium confidence) — [source](https://nodejs.org/download/release/v22.14.0/docs/api/cli.html) · [also](https://docs.newrelic.com/docs/apm/agents/nodejs-agent/installation-configuration/install-nodejs-agent/) · [also](https://raw.githubusercontent.com/nodejs/node/v22.14.0/doc/changelogs/CHANGELOG_V22.md)
- New Relic instructs users to generate application traffic and wait a few minutes for APM data. Its troubleshooting guide warns that short-lived tests may exit before data is reported and that configuration, framework or Apdex settings can explain missing transaction traces. The default agent log is newrelic_agent.log in the application directory unless logging settings have changed. (medium confidence) (verified as of 2026-11-02) — [source](https://docs.newrelic.com/docs/apm/agents/nodejs-agent/installation-configuration/install-nodejs-agent/) · [also](https://docs.newrelic.com/docs/apm/agents/nodejs-agent/troubleshooting/troubleshoot-your-nodejs-installation/)
- In a separate ESM issue, rChaoz reported an empty database tab despite manually created `newrelic.startSegment()` segments. A maintainer explained that recording database segments and attributes requires appropriate shim methods. The reporter later named SvelteKit and Prisma. This attributed exchange illustrates the distinction between custom segments and database telemetry; it does not establish MongoDB or Mongoose version support. (low confidence) — [source](https://github.com/newrelic/node-newrelic/issues/3201)
