【问题标题】:How do I integrate NewRelic into a Node Typescript Express server bundled with Webpack?如何将 NewRelic 集成到与 Webpack 捆绑的 Node Typescript Express 服务器中?
【发布时间】:2020-03-04 08:39:40
【问题描述】:

坦率地说,我都试过了。我不是 Webpack 的高手,但是这些年来我在配置新项目方面似乎相处得很好。

我现在似乎无法将 NewRelic 服务设置到现有的 Node/Typescript/Express/Webpack 应用程序中。

就目前而言,我的应用程序被很好地捆绑到我的 /dist 文件夹中的单个文件中,并且运行快速灵活。似乎 New Relic 推出的这个“节点代理”不能很好地与 Typescript 导入配合使用。

Webpack 配置

const path = require('path');
const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');
const NodemonPlugin = require ('nodemon-webpack-plugin');

module.exports = (env = {}) => {
const config = {
    entry: ['./src/app.ts'],
    mode: env.development ? 'development' : 'production',
    target: 'node',
    devtool: env.development ? 'inline-source-map' : false,
    resolve: {
        extensions: ['.ts', '.js'],
        modules: ['node_modules', 'src', 'package.json'],
    },
    module: {
        rules: [
            {
                test: /\.ts$/,
                use: ['ts-loader', 'eslint-loader'],
                // exclude: /node_modules/,
            },
        ],
    },
    plugins: [],
    externals: [ 'newrelic', nodeExternals() ]
};

if (env.nodemon) {
    config.watch = true;
    config.plugins.push(new NodemonPlugin())
}
return config;
};
  • 存在标准的 /project_root/.newrelic 文件
  • CircleCi 选择了这个项目并从 package.json ==> "webpack" 运行 "build:ci" 脚本
  • 输出是/dist/main.js

参考资料
https://docs.newrelic.com/docs/agents/nodejs-agent/installation-configuration/install-nodejs-agent https://docs.newrelic.com/docs/agents/nodejs-agent/installation-configuration/nodejs-agent-configuration https://discuss.newrelic.com/t/node-agent-fails-with-webpack/24874

【问题讨论】:

    标签: node.js typescript express newrelic


    【解决方案1】:

    您的应用程序起点的第一行应该是

    import newrelic from 'newrelic';
    

    当然,先运行 npm install newrelic --save

    然后,在 repo 的根目录(在 src 之外)创建一个 newrelic.js 文件。

    然后你输入如下细节:

    'use strict'
    exports.config = {
      app_name: ['appName'],
      license_key: '1234567890',
      allow_all_headers: true,
      attributes: {
        exclude: [
          'request.headers.cookie',
          'request.headers.authorization',
          'request.headers.proxyAuthorization',
          'request.headers.setCookie*',
          'request.headers.x*',
          'response.headers.cookie',
          'response.headers.authorization',
          'response.headers.proxyAuthorization',
          'response.headers.setCookie*',
          'response.headers.x*'
        ]
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-07
      • 1970-01-01
      • 2018-08-23
      • 1970-01-01
      • 2019-10-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多