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
  • Loading branch information
isra17 committed Oct 21, 2022
1 parent 9beb6b2 commit 1b47344
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.13.0-0.34b0...HEAD)
- Urllib3 instrumentation can now retrieve urlopen body parameter when used as positional
([#1398](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1398))
- Add metric instrumentation for tornado
([#1252](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1252))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,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 1b47344

Please sign in to comment.