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().
@ -20,9 +23,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fix bug in Urllib instrumentation - add status code to span attributes only if the status code is not None.
- Fix bug in Urllib instrumentation - add status code to span attributes only if the status code is not None.
([#1430](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1430))
- `opentelemetry-instrumentation-aiohttp-client` Allow overriding of status in response hook.
- `opentelemetry-instrumentation-aiohttp-client` Allow overriding of status in response hook.
([#1394](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1394))
- `opentelemetry-instrumentation-pymysql` Fix dbapi connection instrument wrapper has no _sock member.
([#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
### Added
- `opentelemetry-instrumentation-grpc` add supports to filter requests to instrument.
- `opentelemetry-instrumentation-grpc` add supports to filter requests to instrument.
([#1241](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1241))
- Flask sqlalchemy psycopg2 integration
([#1224](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1224))

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)