Skip to content

Commit

Permalink
fix(gevent): ensure gevent is patched automatically (#3202)
Browse files Browse the repository at this point in the history
`gevent` was in `_PATCH_ON_IMPORT` but not `PATCH_MODULES` so was not getting picked up for patching.
  • Loading branch information
brettlangdon authored Feb 1, 2022
1 parent 17a3397 commit 78405d7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions ddtrace/_monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"elasticsearch": True,
"algoliasearch": True,
"futures": True,
"gevent": True,
"grpc": True,
"httpx": True,
"mongoengine": True,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
Ensure ``gevent`` is automatically patched.
31 changes: 31 additions & 0 deletions tests/contrib/gevent/test_monkeypatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,34 @@ def test_gevent_warning(monkeypatch):
assert subp.wait() == 0
assert subp.stdout.read() == b""
assert b"RuntimeWarning: Loading ddtrace before using gevent monkey patching" in subp.stderr.read()


def test_gevent_auto_patching(run_python_code_in_subprocess):
code = """
import ddtrace; ddtrace.patch_all()
import gevent # Patch on import
from ddtrace.contrib.gevent import GeventContextProvider
assert isinstance(ddtrace.tracer.context_provider, GeventContextProvider)
"""

out, err, status, pid = run_python_code_in_subprocess(code)
assert status == 0, err
assert out == b""


def test_gevent_ddtrace_run_auto_patching(ddtrace_run_python_code_in_subprocess):
code = """
import gevent # Patch on import
import ddtrace # ddtrace-run, No need to call patch_all()
from ddtrace.contrib.gevent import GeventContextProvider
assert isinstance(ddtrace.tracer.context_provider, GeventContextProvider)
"""

out, err, status, pid = ddtrace_run_python_code_in_subprocess(code)
assert status == 0, err
assert out == b""

0 comments on commit 78405d7

Please sign in to comment.