mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-30 05:32:30 +08:00
Urllib3 instrumentation can now retrieve urlopen body parameter when used as positional (#1398)
This commit is contained in:
@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## Unreleased
|
||||
|
||||
- Add metric instrumentation for tornado
|
||||
([#1252](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1252))
|
||||
|
||||
### Added
|
||||
|
||||
- `opentelemetry-instrumentation-pymysql` Add tests for commit() and rollback().
|
||||
|
@ -118,6 +118,7 @@ _ResponseHookT = typing.Optional[
|
||||
_URL_OPEN_ARG_TO_INDEX_MAPPING = {
|
||||
"method": 0,
|
||||
"url": 1,
|
||||
"body": 2,
|
||||
}
|
||||
|
||||
|
||||
|
@ -309,3 +309,24 @@ class TestURLLib3Instrumentor(TestBase):
|
||||
)
|
||||
self.assertIn("request_hook_body", span.attributes)
|
||||
self.assertEqual(span.attributes["request_hook_body"], body)
|
||||
|
||||
def test_request_positional_body(self):
|
||||
def request_hook(span, request, headers, body):
|
||||
span.set_attribute("request_hook_body", body)
|
||||
|
||||
URLLib3Instrumentor().uninstrument()
|
||||
URLLib3Instrumentor().instrument(
|
||||
request_hook=request_hook,
|
||||
)
|
||||
|
||||
body = "param1=1¶m2=2"
|
||||
|
||||
pool = urllib3.HTTPConnectionPool("httpbin.org")
|
||||
response = pool.urlopen("POST", "/status/200", body)
|
||||
|
||||
self.assertEqual(b"Hello!", response.data)
|
||||
|
||||
span = self.assert_span()
|
||||
|
||||
self.assertIn("request_hook_body", span.attributes)
|
||||
self.assertEqual(span.attributes["request_hook_body"], body)
|
||||
|
Reference in New Issue
Block a user