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

MySQL Pooled queries have the wrong parent #175

Closed
fragglebob opened this issue Jul 10, 2018 · 5 comments
Closed

MySQL Pooled queries have the wrong parent #175

fragglebob opened this issue Jul 10, 2018 · 5 comments
Labels
bug Something isn't working community integrations

Comments

@fragglebob
Copy link
Contributor

I noticed in DataDog that none of my traces had database calls, except for the first query, which seemed to have them all belong to it.

After loads of debugging I worked out its down to the current span in the query being the span that creates the connection.

My solution for now was to stop using pool.query and use pool.getConnection, however I had to bind the callback to get the correct span for the query.

pool.getConnection(tracer.bind((err, conneciton) => {
    connection.query(sql, values, cb)
}))

The problem happens in pool.acquireConnection, when it enters onOperationComplete the span is changed to that original one.

@rochdev rochdev added bug Something isn't working community integrations labels Jul 10, 2018
@fragglebob fragglebob changed the title MySQL Pooled queries in the wrong have the wrong parent MySQL Pooled queries have the wrong parent Jul 10, 2018
@rochdev
Copy link
Member

rochdev commented Jul 10, 2018

I cannot reproduce this issue specifically since the provided snippet gives me the correct span. I was however able to cause a similar issue related to the internal queue of the mysql module.

@fragglebob If I open a PR, would you be able to try it out directly?

@fragglebob
Copy link
Contributor Author

The snippet I shared produces the correct span. It's the way I've got round the issue for now.

Sure, I can give it a go tomorrow.

@rochdev
Copy link
Member

rochdev commented Jul 10, 2018

I meant that even without tracer.bind() it still works for me, even if I run multiple queries.

Here's the PR: #178

@fragglebob
Copy link
Contributor Author

I get ya now.

I think it might have been from using a combination of express, graphql and mysql together. I will give it a go tomorrow. 👍

If I get some time I will figure out how to cause it in a smaller example.

@fragglebob
Copy link
Contributor Author

Yep, that fixes it completely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working community integrations
Projects
None yet
Development

No branches or pull requests

2 participants