I am new to node js and was trying to integrate zipkins with my node APi using appmetrics-zipkin npm package. Zipkin works fine except when there are multiple http calls in async parallel method , it gives trace of only the first http call which was finished...I need trace for all the API calls in async parallel......Please help
Asked
Active
Viewed 136 times
1 Answers
0
Well, without seeing any code, I could only give you a sample of how you should achieve this. So an http call, for example if you use node-fetch or axios will return a promise. To wait for promises paralelly, you can do the following:
async function myParallelRequests() {
const requestOne = fetch(urlOne);
const requestTwo = fetch(urlTwo);
const requestThree = fetch(urlThree);
const [responseOne, responseTwo, responseThree] = await Promise.all([
requestOne,
requestTwo,
requestThree,
]);
}
Note that I use fetch API here, provided in node by the node-fetch package. Fetch returns a Promise
. Then I call Promise.all(promises)
where promises
is a Promise
array. You can then do whatever you would like to do with the 3 responses and your requests were made paralelly.
Hope this helps, good luck!

f4z3k4s
- 966
- 7
- 13