[Node] Process time isn't correct?

Hello,
I’m not sure if this is the correct category to post my question. I’m having this Node background transaction

nr.startBackgroundTransaction('9:9', async () => {
 const transaction = nr.getTransaction();
 const message = '================test================';
 await SocketService.updateFriendQueues(message, (data) => {
   console.log(data);
   transaction.end();
 });
});

And here’s the sample updateFriendQueues function

static async updateFriendQueues(message, callback) {
 setTimeout(() => {
  console.log(message);
  callback('test');
 }, 10000);
}

And it already prints the log after 10 seconds but in the transactions section I find that this transaction took 2.12 ms only though the transaction ends after 10 seconds. Is there any thing wrong with my sample code? What’s the issue here?

I also tried this

nr.startBackgroundTransaction('5:5', async () => {
 const transaction = nr.getTransaction();
 const message = '=============test===============';
 await SocketService.updateFriendQueues(message, transaction);
});

static async updateFriendQueues(message, transaction) {
setTimeout(() => {
  console.log(message);
  transaction.end();
  }, 10000);
}

Annotation 2021-06-08 145550

But that didn’t work too and time is still not correct.

When I tried without async/await it worked fine and timing is correct

nr.startBackgroundTransaction('2:2', () => {
 const transaction = nr.getTransaction();
 setTimeout(() => {
   console.log('test test test');
   transaction.end();
 }, 10000);
});

So why it’s not correct while using async/await and how to fix this? Thanks in advance for your help

Hello @y.sharaf

Our tracing feature doesn’t try to distinguish when a root span from an async service, so it might send a response while work is still ongoing.
There is a difference between response time and total time which can found in Response time chart types (APM and browser) | New Relic Documentation

This topic was automatically closed after 365 days. New replies are no longer allowed.