Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Child traces not associated with correct parent #9

Open
bryanlarsen opened this issue Oct 13, 2017 · 7 comments
Open

Child traces not associated with correct parent #9

bryanlarsen opened this issue Oct 13, 2017 · 7 comments

Comments

@bryanlarsen
Copy link
Contributor

I added a 5 second delay to the server1 example in jaeger-node, and then did a few simultaneous requests. All child spans showed up as children of the first request, no child spans were associated with the subsequent requests.

@hekike
Copy link
Contributor

hekike commented Oct 19, 2017

@bryanlarsen do you have an idea why? I mean did you collect more information about this issue in the meantime?

@bryanlarsen
Copy link
Contributor Author

No, I just dismissed opentracing-auto as broken by design.

The problem is trivial to reproduce with simultaneous requests to your example.

It'd require some pretty cool magic for the mongo wrapper to know which http request triggered the mongo call if there is more than one http request outstanding. I'd love to get some of that magic if there is some, but it looks like your code is fairly straightforward, not magical.

@hekike
Copy link
Contributor

hekike commented Oct 25, 2017

The "magic" is called continuation-local-storage and maybe there is a bug in this library but it is possible.

@bryanlarsen
Copy link
Contributor Author

That is pretty magical! Thanks for the pointer.

A quick googling indicates that this isn't an uncommon occurrence, a good explanation is in the bottom section of https://datahero.com/blog/2014/05/22/node-js-preserving-data-across-async-callbacks/

The first thing I would suspect would be the mongodb connection pool -- the mongodb connection would have been created on the first request and reused for the second request, so it uses the local storage of the first request. Just a guess, though, could be something else. Something like https://github.com/tylerchr/cls-porqpine is probably needed in the example code.

I'll try and setup my test environment and try and get you either a PR or a better request. Won't be able to get to it today, though.

@hekike
Copy link
Contributor

hekike commented Oct 26, 2017

You are right, we cannot track absolutely everything.
RIght now the express / restify request handlers are the entry points (root span).

In the meantime, I replaced the asynctx library to the widely adopted cls-hooked, could you re-evaluate opentracing-auto?

Relased to npm as v1.5.2

@Puneeth-n
Copy link

@bryanlarsen any updates on #9 (comment)?

@leopoldodonnell
Copy link

Looks like cls-hooked doesn't really improve things. I experimented by augmenting with async-local-storage to squirrel away the root context (if one existed). I could also just verify there isn't a root-context in the stack, but that could give me the wrong root context on a busy server.

The challenge is to connect a pooled connection created with an earlier context to the present one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants