Skip to content

Commit

Permalink
docs(node.js) Add instrumenting already loaded module
Browse files Browse the repository at this point in the history
Provide additional information for instrumenting supported node.js modules that have been already loaded for cases where a user may have to delay instrumenting. An example of this might be asynchronously loading and decrypting api keys from a remote location.
  • Loading branch information
keithmorris committed May 13, 2022
1 parent 26f10af commit a9be52d
Showing 1 changed file with 15 additions and 0 deletions.
Expand Up @@ -70,6 +70,21 @@ To install the Node.js agent:
```
node -r newrelic ./dist/server.js
```
If you are unable to `require('newrelic');` as the first line of your app's main module and you are unable to use the require flag as above (e.g. asynchronously loading api keys from a remote location during application bootstrapping), you may also add stock instrumentation to an already loaded [supported module](https://github.com/newrelic/node-newrelic/blob/0113eb5f0e707dc662a17d262a841503bab88841/lib/instrumentations.js#L6#L6) by using [`newrelic.instrumentLoadedModule`](https://docs.newrelic.com/docs/apm/agents/nodejs-agent/api-guides/nodejs-agent-api/#instrumentLoadedModule):

```js
// load the agent
const newrelic = require('newrelic');

// module loaded before newrelic
const expressModule = require('express');

// instrument express after the agent has been loaded
newrelic.instrumentLoadedModule(
'express', // the module's name, as a string
expressModule // the module instance
);
```
</Callout>

7. Optional: For additional [Node.js runtime-level statistics](/docs/agents/nodejs-agent/supported-features/node-vms-statistics-page), ensure the [`@newrelic/native-metrics` package is installed](/docs/agents/nodejs-agent/supported-features/node-vm-measurements).
Expand Down

0 comments on commit a9be52d

Please sign in to comment.