Newrelic.js not working with Typescript NodeJs Express App

Viewed 389

I want to integrate Newrelic for my Typescript NodeJs Express Application, I have done these changes

to install newrelic

npm install newrelic // to install newrelic

Added a file named newrelic.js outside src folder like this

'use strict'
exports.config = {
  app_name: ['App Name'],
  license_key: 'xxxx',
  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*'
    ]
  }
}

with the correct app name and license_key. And added

import newrelic from 'newrelic';

at the start of my index.ts file (which is the start of my application). And I am using ts-node to start up my application like

ts-node src/index.ts

I am not seeing any data on my newrelic dashboard. I tried searching newrelic for typescript nodejs express app but found nothing that will help.

Is something wrong here?

1 Answers

Encountered a similar problem, had hooked up the newrelic module as above but wasn't seeing any APM data in NR. (I'm also using ts-node to run my apps.)

In the end, after reading the info on https://typestrong.org/ts-node/docs/configuration#node-flags and step 6 on https://docs.newrelic.com/docs/apm/agents/nodejs-agent/installation-configuration/install-nodejs-agent/ I updated the start command in my package.json from

"start": "ts-node -T -r tsconfig-paths/register ./src/index.ts",

to

"start": "NODE_OPTIONS='-r newrelic' ts-node -T -r tsconfig-paths/register ./src/index.ts", to preload the newrelic module before starting the main app.

After that I started to see the APM data being collected

Related