Urllib3 instrumentation can now retrieve urlopen body parameter when used as positional (#1398)

This commit is contained in:
Israël Hallé
2022-11-15 20:30:22 -05:00
committed by GitHub
parent ffb995d28b
commit 725944d368
3 changed files with 28 additions and 3 deletions

View File

@ -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().

View File

@ -118,6 +118,7 @@ _ResponseHookT = typing.Optional[
_URL_OPEN_ARG_TO_INDEX_MAPPING = {
"method": 0,
"url": 1,
"body": 2,
}

View File

@ -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&param2=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)