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

[django] Fix gunicorn gevent worker causing database connection unpatch #442

Merged
merged 2 commits into from
Mar 28, 2018

Conversation

willgittoes-dd
Copy link
Contributor

When running django via gunicorn and using gevent workers new connections are created after a greenlet fork, and they are unpatched. That results in still seeing django traces but losing DB traces.

This simply makes connection patching slightly more robust, by patching the ConnectionHandler object. The patched ConnectionHandler makes sure that every connection it handles is patched.

…ew connections that are created get patched too. Fixes issue where running under gunicorn>gevent>django misses tracing on DB connections.
@willgittoes-dd willgittoes-dd requested review from palazzem and clutchski and removed request for clutchski and palazzem March 27, 2018 07:56
@willgittoes-dd
Copy link
Contributor Author

Sorry, un-assigning reviewers for now because I thought about a better way to do this, although testing it is going to suck.

@willgittoes-dd
Copy link
Contributor Author

Actually my 'better method' was not possible. I wanted to not patch the ConnectionHandler but patch the Database to ensure new connections get the TracedCursor added. But gevent creates a new Database object for each greenlet, so I do indeed need to patch ConnectionHandler as I originally did.

@palazzem palazzem added this to the 0.12.0 milestone Mar 28, 2018
@palazzem palazzem changed the base branch from master to 0.12-dev March 28, 2018 13:22
@palazzem palazzem changed the base branch from 0.12-dev to master March 28, 2018 13:25
@palazzem palazzem modified the milestones: 0.12.0, 0.11.1 Mar 28, 2018
Copy link

@palazzem palazzem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should address the problem. Can we replicate the issue with/without this patch in a real application?

@willgittoes-dd
Copy link
Contributor Author

Yes, I can replicate this with a real (toy) application, not just in tests. That's how I developed the fix. Then I added tests (ensuring the fail without the fix, of course).

Repro steps:

  1. Take the Datadog APM django example project: https://github.com/DataDog/trace-examples/tree/master/python/django
  2. Run with gunicorn gettingstarted.wsgi:application --bind localhost:8080 --worker-class sync
  3. Observe django and defaultdb traces
  4. Run with gunicorn gettingstarted.wsgi:application --bind localhost:8080 --worker-class gevent
  5. Observe only django traces.

@willgittoes-dd willgittoes-dd merged commit 3f02d59 into master Mar 28, 2018
@willgittoes-dd willgittoes-dd deleted the willgittoes-dd/gunicorn-gevent-bug branch March 28, 2018 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants