Skip to content

Commit

Permalink
adding up to date generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
ItayGibel-helios committed Sep 2, 2021
1 parent 42995da commit 76f1f23
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,13 @@ def instrumented_urlopen(wrapped, instance, args, kwargs):
)


def _call_request_hook(request_hook: typing.Union[_RequestHookT, _ExtendedRequestHookT],
span: Span,
connection_pool: urllib3.connectionpool.HTTPConnectionPool,
headers: typing.Dict,
body: str):
def _call_request_hook(
request_hook: typing.Union[_RequestHookT, _ExtendedRequestHookT],
span: Span,
connection_pool: urllib3.connectionpool.HTTPConnectionPool,
headers: typing.Dict,
body: str,
):
try:
# First assume request_hook is a function of type _ExtendedRequestHookT
request_hook(span, connection_pool, headers, body)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def setUp(self):
httpretty.register_uri(httpretty.GET, self.HTTPS_URL, body="Hello!")
httpretty.register_uri(httpretty.POST, self.HTTP_URL, body="Hello!")


def tearDown(self):
super().tearDown()
URLLib3Instrumentor().uninstrument()
Expand Down Expand Up @@ -288,21 +287,23 @@ def extended_request_hook(span, request, headers, body):
span.set_attribute("request_hook_body", body)

URLLib3Instrumentor().uninstrument()
URLLib3Instrumentor().instrument(
request_hook=extended_request_hook,
)
URLLib3Instrumentor().instrument(request_hook=extended_request_hook,)

headers = {"header1": "value1", "header2": "value2"}
body = "param1=1&param2=2"

pool = urllib3.HTTPConnectionPool("httpbin.org")
response = pool.request("POST", "/status/200", body=body, headers=headers)
response = pool.request(
"POST", "/status/200", body=body, headers=headers
)

self.assertEqual(b"Hello!", response.data)

span = self.assert_span()

self.assertIn("request_hook_headers", span.attributes)
self.assertEqual(span.attributes["request_hook_headers"], json.dumps(headers))
self.assertEqual(
span.attributes["request_hook_headers"], json.dumps(headers)
)
self.assertIn("request_hook_body", span.attributes)
self.assertEqual(span.attributes["request_hook_body"], body)

0 comments on commit 76f1f23

Please sign in to comment.