Skip to content

Commit 1b47344

Browse files
committed
Urllib3 instrumentation can now retrieve urlopen body parameter when used as positional
1 parent 9beb6b2 commit 1b47344

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.13.0-0.34b0...HEAD)
9+
- Urllib3 instrumentation can now retrieve urlopen body parameter when used as positional
10+
([#1398](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1398))
911
- Add metric instrumentation for tornado
1012
([#1252](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1252))
1113

instrumentation/opentelemetry-instrumentation-urllib3/src/opentelemetry/instrumentation/urllib3/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def response_hook(span, request, response):
117117
_URL_OPEN_ARG_TO_INDEX_MAPPING = {
118118
"method": 0,
119119
"url": 1,
120+
"body": 2,
120121
}
121122

122123

instrumentation/opentelemetry-instrumentation-urllib3/tests/test_urllib3_integration.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,3 +309,24 @@ def request_hook(span, request, headers, body):
309309
)
310310
self.assertIn("request_hook_body", span.attributes)
311311
self.assertEqual(span.attributes["request_hook_body"], body)
312+
313+
def test_request_positional_body(self):
314+
def request_hook(span, request, headers, body):
315+
span.set_attribute("request_hook_body", body)
316+
317+
URLLib3Instrumentor().uninstrument()
318+
URLLib3Instrumentor().instrument(
319+
request_hook=request_hook,
320+
)
321+
322+
body = "param1=1&param2=2"
323+
324+
pool = urllib3.HTTPConnectionPool("httpbin.org")
325+
response = pool.urlopen("POST", "/status/200", body)
326+
327+
self.assertEqual(b"Hello!", response.data)
328+
329+
span = self.assert_span()
330+
331+
self.assertIn("request_hook_body", span.attributes)
332+
self.assertEqual(span.attributes["request_hook_body"], body)

0 commit comments

Comments
 (0)