Skip to content

Instantly share code, notes, and snippets.

@benhartley
Created September 16, 2015 09:37
Show Gist options
  • Save benhartley/febdb500bb707d987609 to your computer and use it in GitHub Desktop.
Save benhartley/febdb500bb707d987609 to your computer and use it in GitHub Desktop.
New Relic examples
// Some of this is pseudo-code / redacted...
function get(routeName, params, res) {
...
return cache.get('hget', cacheKey, 'json')
.then(r => {
newRelic.endTransaction();
return r;
})
.catch(...);
}
module.exports = {
get: newRelic.createBackgroundTransaction('morph:get', get)
};
// Some of this is pseudo-code / redacted...
function route(routeName) {
return (req, res) => {
...
return res.format({
'text/html': () => {
...
return cache.get('get', cacheKey)
.then(res.send.bind(res))
.catch(...);
},
'application/json': () => {
return module.method(args)
.then(res.send.bind(res))
.catch((error) => {
...
return res.sendStatus(500);
});
}
});
};
}
module.exports = {
route: newRelic.createTracer('cachedRoute', route)
};
// Some of this is pseudo-code / redacted...
function get() {
return bluebird.props({
key: val
})
.then(orb => {
newRelic.endTransaction();
return orb;
});
}
module.exports = {
get: newRelic.createWebTransaction('orb:get', get)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment