Node 8 / Async: Auto-Correlation support
See original GitHub issueTL/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:
- Created 5 years ago
- Reactions:7
- Comments:19 (11 by maintainers)

Top Related StackOverflow Question
@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.@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.