question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Node 8 / Async: Auto-Correlation support

See original GitHub issue

TL/DR Auto dependency correlation appears to fail in all but the most trivial async/await scenarios. I understand that you can’t always rely on context propagation in nodejs but this seems too simple to be expected.

In more detail Everything I’m about to say can be reproduced from this gist.

Recently I converted an existing application from a node 6 web API to node 8 and began updating the code-base to leverage async/await functionality. This application integrates with various Azure PaaS systems including Cosmos DB and Azure Storage. Everything was working great until we checked our application insights integration. I noticed that all of the data was there but all of a sudden our tracing and dependency correlation was broken.

Checking the issues page I thought it may be related to #296 (our application is quite complex) so I tried to boil it down to the simplest of repro steps - and it really was simple.

Looking at the gist you’ll see that executing 1 async operation generates perfectly good dependency correlation curl http://localhost:3000/endpoint/simple

Type Operation Id Request Url
RemoteDependencyData 987D4A34-7228-428F-B366-C007EA54C8D8 987D4A34-7228-428F-B366-C007EA54C8D8.1 https://github.com:443/Microsoft/ApplicationInsights-node.js/
RequestData 987D4A34-7228-428F-B366-C007EA54C8D8 987D4A34-7228-428F-B366-C007EA54C8D8. http://localhost:3000/endpoint/simple

But executing a series of identical async operations will drop the context half-way through the request curl http://localhost:3000/endpoint/complex

Type Operation Id Request Url
RemoteDependencyData 2199F028-C94E-4A61-BCE3-9C019390A632 2199F028-C94E-4A61-BCE3-9C019390A632.1. https://github.com:443/Microsoft/ApplicationInsights-node.js/
RemoteDependencyData undefined 2AA17EDD-073D-4538-9D87-4920E52FC1A7 https://github.com:443/Microsoft/ApplicationInsights-node.js/
RemoteDependencyData undefined 19AC35E4-50F7-4091-B19D-8B5205559D0C https://github.com:443/Microsoft/ApplicationInsights-node.js/
RemoteDependencyData undefined 7B41AD91-91B4-47DD-9D30-CE536E81953A https://github.com:443/Microsoft/ApplicationInsights-node.js/
RemoteDependencyData undefined 032F748C-B57C-4F79-A187-F954166FD1B9 https://github.com:443/Microsoft/ApplicationInsights-node.js/
RequestData 2199F028-C94E-4A61-BCE3-9C019390A632 2199F028-C94E-4A61-BCE3-9C019390A632. http://localhost:3000/endpoint/complex

But switching this to either a promise chain or a generator based solution produces perfect correlation curl http://localhost:3000/endpoint/chained

Type Operation Id Request Url
RemoteDependencyData DC7B1746-5ED7-40AB-8557-31C71BF1132A DC7B1746-5ED7-40AB-8557-31C71BF1132A.1. https://github.com:443/Microsoft/ApplicationInsights-node.js/
RemoteDependencyData DC7B1746-5ED7-40AB-8557-31C71BF1132A DC7B1746-5ED7-40AB-8557-31C71BF1132A.2. https://github.com:443/Microsoft/ApplicationInsights-node.js/
RemoteDependencyData DC7B1746-5ED7-40AB-8557-31C71BF1132A DC7B1746-5ED7-40AB-8557-31C71BF1132A.3. https://github.com:443/Microsoft/ApplicationInsights-node.js/
RemoteDependencyData DC7B1746-5ED7-40AB-8557-31C71BF1132A DC7B1746-5ED7-40AB-8557-31C71BF1132A.4. https://github.com:443/Microsoft/ApplicationInsights-node.js/
RemoteDependencyData DC7B1746-5ED7-40AB-8557-31C71BF1132A DC7B1746-5ED7-40AB-8557-31C71BF1132A.5. https://github.com:443/Microsoft/ApplicationInsights-node.js/
RequestData DC7B1746-5ED7-40AB-8557-31C71BF1132A DC7B1746-5ED7-40AB-8557-31C71BF1132A. http://localhost:3000/endpoint/chained

Environment:

  • OS: Windows
  • Node Version: 8.11.0
  • 3rd party libraries: none (beyond the chosen web framework)

I understand that you can’t always rely on context propagation in nodejs but this seems too simple to be expected.

Am I doing something wrong? Is this the same issue as #296?

Please advise.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:19 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
markwolffcommented, Jan 30, 2019

@GavinOsborn It has been released to stable now (1.1.0). I’m pretty confident it will be more reliable than our previous zone.js implementation.

1reaction
OsvaldoRosadocommented, Jan 30, 2019

@GavinOsborn as far as “use at your own risk” is concerned, I wouldn’t expect anything like application crashes. (and as @markwolff says, it’s certainly a lot more stable than our zone implementation was in this regard 😄) The underlying Node APIs are indeed non-final, but that’s more of a problem of our SDK updating to support newer versions of Node when/if the APIs change.

The main thing to watch is if your particular workload gets a noticably higher performance overhead from the underlying V8 async/await monitoring that upgrading Node versions doesn’t mitigate.

Read more comments on GitHub >

github_iconTop Results From Across the Web

New Relic APM Now Supports Node 8
With Version 2.3.0 of the New Relic Node.js agent, our support for the async/await keywords with Node 8 is now enabled by default....
Read more >
How to Use Async Await With Node.js 8.0.0 - Peter Forgacs
In my opinion async await can help you write easier to understand and maintainable code but it requires at least a minimal understanding...
Read more >
Async Await in Node.js - How to Master it? - Blog - RisingStack
Learn how to use async await in Node.js (async functions) to simplify your callback or Promise based application.
Read more >
Performance guidelines for Async/Await in Node Version 8
The question asked is about try/catch performance with async/await in nodejs version 8 which you've not really offered any definitive ...
Read more >
Using Async Await in Express with Node 14 | by Alex Bazhenov
Since the arrival of node v 7.6.0 async / await has been supported in node by default. If you're using Node 8.0+ there...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found