New Relic Webpack Plugin

Use the NodeJS agent with your webpack compiled server side javascript project.

New Relic Webpack Plugin

An experimental plugin to allow New Relic's NodeJS Agent to work with webpack compiled server side javascript. This plugin does not instrument any frontend javascript frameworks -- please see New Relic's browser agent documentation for more information on monitoring frontend javascript frameworks.

Quick Start

Add the plugin to your project

1$ npm install @newrelic/webpack-plugin

and then add and externals and plugins section to your webpack configuration like this.

1/*...*/
2
3 const nodeExternals = require('@newrelic/webpack-plugin/lib/externals')
4 const NewrelicWebpackPlugin = require('@newrelic/webpack-plugin/lib/NewrelicWebpackPlugin')
5
6 module.exports = {
7 /* ... */
8 externals: [nodeExternals()],
9 plugins: [
10 new NewrelicWebpackPlugin()
11 ]
12 /* ... */
13 }

How This Works

In order to use Newrelic's NodeJS agent with webpack, you'll need to

  1. Ensure the modules New Relic instruments are listed as webpack externals.
  2. Add require('newrelic') to the top of your generated sources.

This package allows you to do both. The nodeExternals function

1const nodeExternals = require('newrelic-webpack-plugin/lib/externals')
2
3 /* ... */
4
5 module.exports = {
6 /* ... */
7 externals: [nodeExternals()],
8 /* ... */
9 }

is borrowed from webpack-node-externals, which is the de-facto standard way to use webpack with NodeJS server side projects. If a module the agent instruments is not listed as a webpack external, the agent will not function properly.

The NewrelicWebpackPlugin

1const NewrelicWebpackPlugin = require('newrelic-webpack-plugin/lib/NewrelicWebpackPlugin')
2
3 module.exports = {
4 /* ... */
5 plugins: [
6 new NewrelicWebpackPlugin()
7 ]
8 /* ... */
9 }

ensures that a require('newrelic') statment is added to the top of any .js asset file generated by webpack.

Contributions

New Relic Webpack Plugin accepts contributions under our open source Code of Conduct.

Issues / Enhancement Requests

Issues and enhancement requests can be submitted in the Issues tab of this repository. Please search for and review the existing open issues before submitting a new issue.

Code Contributions

Code contributions are welcome. Please review our Contributors Guide and review the Issues list. New Relic open source projects follow a fork-and-pull-request code contribution workflow.

Top Contributors

Thank you to the following and all contributors.