Question

I'm trying to get new relic browser integration working with Sails.js Getting new relic working at applicatin level is quite simple:

var newrelic = require('newrelic');
// Start sails and pass it command line arguments
require('sails').lift(require('optimist').argv);

in app.js

However to get the browser stuff working you need to call newrelic.getBrowserTimingHeader() at the beginning of the html head.

I've tried various things, such as adding newrelic to global, (global.newrelic) but that seems to disappear, adding it to local.js in config, and passing it in to lift as a config override, however that doesn't seem to work either (I'm probably passing it in wrong)

So does anyone have any idea how I can get the newrelic variable from the orginal app.js to the layout file?

Was it helpful?

Solution

So turns out when you run sails lift on the command line it doesn't actually use the app.js file. To use that you have to do node app.js. My app.js now looks like this;

global.newrelic = require('newrelic');
require('sails').lift(require('optimist').argv);

then in layout.ejs you can add

<%- global.newrelic.getBrowserTimingHeader() %>

Putting stuff in the global might not be the best solution, however whenever I put it into the sails.config the object got messed up :(

OTHER TIPS

@cosmorogers First of all, your answer is a perfectly valid way to do this. To clarify, you're creating a new global variable called newrelic whether you attach it to global or not- i.e. newrelic=require('newrelic'); does the same thing.

So turns out when you run sails lift on the command line it doesn't actually use the app.js file

Indeed- and as you mentioned, you can always lift sails with node app.js instead.

Some additional info/commentary here: http://willricketts.com/using-newrelic-with-sails-js/#comment-1551000708

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top