We are trying to use APM for our React nodejs app.
We have added the dependency in our package.json to install the elastic-apm-node module:
"elastic-apm-node": "^3.31.0"
And then we added the below line in our index.js after our imports, but before the start of any other processes:
var apm = require('elastic-apm-node').start()
We get the following error messages we try to run an install of our project:
./node_modules/elastic-apm-node/lib/instrumentation/span.js
Module not found: Can't resolve 'async_hooks' in '\node_modules\elastic-apm-node\lib\instrumentation'
The most common reason for the error you're seeing
./node_modules/elastic-apm-node/lib/instrumentation/span.js
Module not found: Can't resolve 'async_hooks' in '\node_modules\elastic-apm-node\lib\instrumentation'
is a frontend build system trying to resolve the built-in Node.js async_hooks module. You didn't mention it, but I'm guessing that index.js is your root React component?
The Node.js agent will allow you to monitor backend Node.js services and Node.js CLI applications. It will not allow you to monitor a React application, or any other frontend framework. To monitor a React application, you'll want to use the "Real User Monitoring JavaScript agent" (sometimes called the browser agent).
So, if what I've said above about your index.js file is correct, the steps I'd take to fix your problem are
I do have one other question now that we will be going the RUM route. Is there auto-instrumentation if we just add the agent to our project by following the "Using Bundlers" section in the following section:
Or will we not get any useful metrics unless we integrate with React using the Integration instructions that you posted? We are trying to limit the code changes as much as possible. We loved the way that the java agents require no code change as we like to keep APM separate from the code as much as we can.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.