Skip to content

Commit

Permalink
Urllib3 instrumentation can now retrieve urlopen body parameter when …
Browse files Browse the repository at this point in the history
…used as positional (#1398)
  • Loading branch information
isra17 authored Nov 16, 2022
1 parent ffb995d commit 725944d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand All @@ -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))
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def response_hook(span, request, response):
_URL_OPEN_ARG_TO_INDEX_MAPPING = {
"method": 0,
"url": 1,
"body": 2,
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,24 @@ def request_hook(span, request, headers, body):
)
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)

0 comments on commit 725944d

Please sign in to comment.