Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

The Node.js APM Agent and Webpack


#1

UPDATE AS OF 5/20/2019

Version 5.9.0 of the Node.js Agent released the instrumentLoadedModule API call that can be used as a workaround to instrument applications that use Webpack.

Please read more on how to use this API call in our docs here:

For more information as to why the Node.js Agent and the Webpack have troubles working together please continue reading below.


The Node.js application environment is constantly growing and changing. At New Relic, we work diligently to be sure we can meet customers where they are, providing tools to instrument their applications and gain valuable insight for performance tuning and accurate monitoring.

As we continue expanding our instrumentation of popular Node.js modules and frameworks, there remain some modules that can cause issues with the Node.js APM agent. One of these unsupported modules is webpack, and it is my goal here to explain how this tool is used with server-side Node.js applications and why it is currently not supported.

What does webpack do?

Webpack is a module bundler, which can take multiple JavaScript files and combine them into a single file. This is often used to package code written using Node-style (CommonJS) module format for running in web browsers. Some developers also use it to bundle up server-side JavaScript for their Node.js applications.

How does this affect the Node.js APM agent?

When Webpack creates its bundled JavaScript file, it scans all module dependencies defined by the require() function. The final, bundled JavaScript file will then no longer need to require in any external modules when the app starts up.

This causes an issue for the Node.js APM agent, which needs to hook into these modules as they are being loaded in order to properly instrument them. The Node.js APM agent is intended to be used as a tool to instrument server-side Node applications such as Express. It does not on its own provide instrumentation of client-side code running in browsers and should not be used as a part of an “isomorphic” JavaScript code that runs on both the server and client.

What does this mean for me?

At this time, there is currently no way for the Node.js APM agent to gather accurate application information from server-side Node applications using webpack. If you are using webpack to bundle your Node.js server code, please take a moment to stop by our Feature Idea area of the Explorers Hub and add your vote to the webpack support request there.

Feature Idea Topic for webpack Support:

Any additional detail you can provide about how you use this tool and why it is necessary for your server application will be helpful to our product teams as they prioritize what to include on future releases of the agent. (If you are really invested, you can also file a feature request directly with the maintainers of webpack to ask that they add instrumentation hooks that would allow our agent to work with code bundled using webpack!)

Happy monitoring!


Relic Solution: Webpack workaround via externals and instrumentLoadedModule
Node Agent fails with WebPack
The Uninstrumented Modules Banner from the Node Agent
Getting <!-- NREUM: (1) --> when using getBrowserTimingHeader()
Getting strange error when building with gitlab and docker