Integrating newrelic with ibm cloud function actions

Hi,
We are trying to integrate newrelic in cloud function actions which has node js code.
if I run locally its connecting to newrelic but when i try to invoke action in cloud its not connecting.

The command we use is:
zip -r samplenewrelic.zip package.json sample.js newrelic.js node_modules
bx wsk action update ‘ams-cloudant/samplenewrelic’ samplenewrelic.zip --kind nodejs:8

Please can anyone help on this.

Depending on your cloud provider, which is not clear from your post, the New Relic collectors may be blocked.

Hey @papatil2 - let us know if Stefan’s comments on ensuring your network is open for the functions in IBM cloud are helpful. I’d be interested to see if ensuring communication can occur between your functions and our collectors fixes this issue. :slight_smile:

Hi Ryan,
we are working on IBM Cloud functions

Hi stefan,
We are working on IBM cloud functions

Thanks for confirming @papatil2 - have you been able to check the network config within IBM Cloud? As Stefan mentioned, the first step to troubleshoot here is to first ensure your Cloud Functions can reach New Relic’s Data Collectors.

1 Like

Hi Ryan,
I have already approached IBM cloud support for this issue. They said to add sleep and try in the code.
var newrelic = require(‘newrelic’);
function sleep (time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
function main(params) { console.log(“Hi all”); return sleep( 5000).then(() => { console.log(“Hi again”); }); } exports.main = main;

The above code worked also. But we dont want to add any delay in our action. So can you please suggest on this,instead of a fix using delay/sleep, could you look into the newrelic package to see if there’s a deterministic way to know when the newrelic initialization is complete.

Hi, @papatil2: It sounds like your cloud function may be completing before the New Relic agent is able to send its data. This thread has a couple of workarounds:

2 Likes

Hi,
Actually my code is simple. It’s not having any lambdas. newrelic is not working, then our support team suggested to add delay with sleep,then it worked.

var newrelic = require(‘newrelic’);

function main(params) {
console.log(“Hi all”);
}
exports.main = main;

Right. The New Relic agent sends its collected metrics once per minute. If your application does not run for at least one minute, the agent does not have a chance to transmit its data. That’s why calling sleep works: it forces the application to run longer, giving the agent time to send its data.

The thread linked above provides two workarounds: send data manually using Insights custom events, and/or call the shutdown() API to tell the agent to send its data before the application ends.

HI,
I tried with shutdown() as shown below.
var newrelic = require(‘newrelic’);

function main(params) {

console.log("Hi all");
newrelic.shutdown({collectPendingData: true}, (error) => {
    console.log("error: ",error);
    
    process.exit()
  })

}
exports.main = main;

I dont see app_name created in newrelic. I tried with { collectPendingData: true, timeout: 3000 } this option also.

Hey @papatil2 - I think the best advice we can give at this point is to add a wait timer (perhaps more than 3000ms?) to ensure data gets sent, ensure you are using the correct New Relic license key, and along with that it may help to re-invoke the function a few times to ensure there is plenty of data getting sent to New Relic.

Unfortunately, cloud functions is not a supported environment for our agents, which means that we can’t be sure how or if our products will work with it. We will continue to keep you on our list and try to connect you with another customer here who may have experience.

I’m sure there are others in the community who may have had successes with cloud functions in the past who could help.

1 Like