wilmoore / node-env-newrelic

Load newrelic in a 12-factor environment with sane defaults.
MIT License
4 stars 0 forks source link

Issues with newrelic api methods erroring #2

Open dylanbathurst opened 8 years ago

dylanbathurst commented 8 years ago

When instrumenting node-env-newrelic I like having it in the global namespace so I can use it in other files without having to require it. I've set it up like this in my app.js file:

global.newrelic = require('env-newrelic')();

I'm running into errors though on my local development when NEW_RELIC_DISABLED=true but my code uses newrelic api methods in my controllers like:

global.newrelic.addCustomParameter('foo', 'bar');

Have you run into this issue at all? Is there a solution already?

One solution I thought would be to add a default or fallback configuration like console.log or debug to the init

global.newrelic = require('env-newrelic')(console.log);

or

var debug = require('debug')('myapp:*');
global.newrelic = require('env-newrelic')(debug);

Then this module would somehow hijack any method calls such as .addCustomParameter() and replace them with console.log() or debug()

wilmoore commented 8 years ago

If I remember correctly, if disabled, doing require('newrelic') won't return anything. At least that's what I believe to have been the case when I wrote this originally. I am not currently working on a project that is using this so I'd have a hard time testing it.

I think the best solution is to see if on the latest version of the newrelic client you can get back an instance of the newrelic client when NEW_RELIC_ENABLED=false. If that is the case, I'd accept a PR that always does require('newrelic') so the client is always available even if it doesn't actually send anything.

wilmoore commented 8 years ago

Here are all of the available environment variables with descriptions: https://www.npmjs.com/package/newrelic#configuring-the-module