Skip to content

Commit 725944d

Browse files
authored
Urllib3 instrumentation can now retrieve urlopen body parameter when used as positional (#1398)
1 parent ffb995d commit 725944d

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
- Add metric instrumentation for tornado
11+
([#1252](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1252))
12+
1013
### Added
1114

1215
- `opentelemetry-instrumentation-pymysql` Add tests for commit() and rollback().
@@ -20,9 +23,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2023

2124
### Fixed
2225

23-
- Fix bug in Urllib instrumentation - add status code to span attributes only if the status code is not None.
26+
- Fix bug in Urllib instrumentation - add status code to span attributes only if the status code is not None.
2427
([#1430](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1430))
25-
- `opentelemetry-instrumentation-aiohttp-client` Allow overriding of status in response hook.
28+
- `opentelemetry-instrumentation-aiohttp-client` Allow overriding of status in response hook.
2629
([#1394](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1394))
2730
- `opentelemetry-instrumentation-pymysql` Fix dbapi connection instrument wrapper has no _sock member.
2831
([#1424](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1424))
@@ -88,7 +91,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8891

8992
### Added
9093

91-
- `opentelemetry-instrumentation-grpc` add supports to filter requests to instrument.
94+
- `opentelemetry-instrumentation-grpc` add supports to filter requests to instrument.
9295
([#1241](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1241))
9396
- Flask sqlalchemy psycopg2 integration
9497
([#1224](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1224))

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

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

123124

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)