Skip to content

Commit 8b9e394

Browse files
Add method to urllib3 trace (#1130)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent a447772 commit 8b9e394

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

newrelic/hooks/external_urllib3.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,32 @@
1414

1515
from newrelic.api.external_trace import ExternalTraceWrapper
1616
from newrelic.common.object_wrapper import wrap_function_wrapper
17-
from newrelic.hooks.external_httplib2 import (
18-
_nr_wrapper_httplib2_endheaders_wrapper)
17+
from newrelic.hooks.external_httplib2 import _nr_wrapper_httplib2_endheaders_wrapper
1918

2019

2120
def _nr_wrapper_make_request_(wrapped, instance, args, kwargs):
22-
2321
def _bind_params(conn, method, url, *args, **kwargs):
24-
return "%s://%s:%s" % (instance.scheme, conn.host, conn.port)
22+
return method, "%s://%s:%s" % (instance.scheme, conn.host, conn.port)
2523

26-
url_for_apm_ui = _bind_params(*args, **kwargs)
24+
method, url_for_apm_ui = _bind_params(*args, **kwargs)
2725

28-
return ExternalTraceWrapper(wrapped, 'urllib3', url_for_apm_ui)(*args, **kwargs)
26+
return ExternalTraceWrapper(wrapped, "urllib3", url_for_apm_ui, method=method)(*args, **kwargs)
2927

3028

3129
def instrument_urllib3_connectionpool(module):
32-
wrap_function_wrapper(module, 'HTTPSConnectionPool._make_request',
33-
_nr_wrapper_make_request_)
34-
wrap_function_wrapper(module, 'HTTPConnectionPool._make_request',
35-
_nr_wrapper_make_request_)
30+
wrap_function_wrapper(module, "HTTPSConnectionPool._make_request", _nr_wrapper_make_request_)
31+
wrap_function_wrapper(module, "HTTPConnectionPool._make_request", _nr_wrapper_make_request_)
3632

3733

3834
def instrument_urllib3_connection(module):
3935
# Don't combine the instrument functions into a single function. Keep
4036
# the 'connect' monkey patch separate, because it is also used to patch
4137
# urllib3 within the requests package.
4238

43-
wrap_function_wrapper(module, 'HTTPSConnection.endheaders',
44-
_nr_wrapper_httplib2_endheaders_wrapper('urllib3', 'https'))
39+
wrap_function_wrapper(
40+
module, "HTTPSConnection.endheaders", _nr_wrapper_httplib2_endheaders_wrapper("urllib3", "https")
41+
)
4542

46-
wrap_function_wrapper(module, 'HTTPConnection.endheaders',
47-
_nr_wrapper_httplib2_endheaders_wrapper('urllib3', 'http'))
43+
wrap_function_wrapper(
44+
module, "HTTPConnection.endheaders", _nr_wrapper_httplib2_endheaders_wrapper("urllib3", "http")
45+
)

tests/external_urllib3/test_urllib3.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@
4545

4646
@pytest.fixture(scope="session")
4747
def metrics(server):
48-
scoped = [("External/localhost:%d/urllib3/" % server.port, 1)]
48+
scoped = [("External/localhost:%d/urllib3/GET" % server.port, 1)]
4949

5050
rollup = [
5151
("External/all", 1),
5252
("External/allOther", 1),
5353
("External/localhost:%d/all" % server.port, 1),
54-
("External/localhost:%d/urllib3/" % server.port, 1),
54+
("External/localhost:%d/urllib3/GET" % server.port, 1),
5555
]
5656

5757
return scoped, rollup
@@ -162,13 +162,13 @@ def _test():
162162

163163

164164
def test_port_included(server):
165-
scoped = [("External/localhost:%d/urllib3/" % server.port, 1)]
165+
scoped = [("External/localhost:%d/urllib3/GET" % server.port, 1)]
166166

167167
rollup = [
168168
("External/all", 1),
169169
("External/allOther", 1),
170170
("External/localhost:%d/all" % server.port, 1),
171-
("External/localhost:%d/urllib3/" % server.port, 1),
171+
("External/localhost:%d/urllib3/GET" % server.port, 1),
172172
]
173173

174174
@validate_transaction_errors(errors=[])

0 commit comments

Comments
 (0)