Skip to content

Commit af4555b

Browse files
authored
fix(httplib): ensure httplib is patched on import [backport #5287 to 1.10] (#5331)
Backports: #5287 ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/contributing.html#Release-Note-Guidelines) are followed. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Author is aware of the performance implications of this PR as reported in the benchmarks PR comment. ## Reviewer Checklist - [ ] Title is accurate. - [ ] No unnecessary changes are introduced. - [ ] Description motivates each change. - [ ] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [ ] Testing strategy adequately addresses listed risk(s). - [ ] Change is maintainable (easy to change, telemetry, documentation). - [ ] Release note makes sense to a user of the library. - [ ] Reviewer is aware of, and discussed the performance implications of this PR as reported in the benchmarks PR comment.
1 parent ff729d1 commit af4555b

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

ddtrace/_monkey.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from ddtrace.vendor.wrapt.importer import when_imported
77

88
from .constants import IAST_ENV
9+
from .internal.compat import PY2
910
from .internal.logger import get_logger
1011
from .internal.telemetry import telemetry_writer
1112
from .internal.utils import formats
@@ -118,6 +119,7 @@
118119
"futures": ("concurrent.futures",),
119120
"vertica": ("vertica_python",),
120121
"aws_lambda": ("datadog_lambda",),
122+
"httplib": ("httplib" if PY2 else "http.client",),
121123
}
122124

123125
IAST_PATCH = {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
httplib: Fixes an issue with patching of http client upon import
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from ddtrace.contrib.httplib.patch import patch
2+
from ddtrace.internal.compat import PY2
3+
4+
5+
try:
6+
from ddtrace.contrib.httplib.patch import unpatch
7+
except ImportError:
8+
unpatch = None
9+
from tests.contrib.patch import PatchTestCase
10+
11+
12+
class TestHttplibPatch(PatchTestCase.Base):
13+
__integration_name__ = "httplib"
14+
__module_name__ = "httplib" if PY2 else "http.client"
15+
__patch_func__ = patch
16+
__unpatch_func__ = unpatch
17+
18+
def assert_module_patched(self, http_client):
19+
pass
20+
21+
def assert_not_module_patched(self, http_client):
22+
pass
23+
24+
def assert_not_module_double_patched(self, http_client):
25+
pass

0 commit comments

Comments
 (0)