示例#1
0
 def validate_url(self, expected_url):
     OpenTelemetryMiddleware._add_request_attributes(  # noqa pylint: disable=protected-access
         self.span, self.environ)
     attrs = {
         args[0][0]: args[0][1]
         for args in self.span.set_attribute.call_args_list
     }
     self.assertIn("http.url", attrs)
     self.assertEqual(attrs["http.url"], expected_url)
     self.assertIn("http.host", attrs)
     self.assertEqual(attrs["http.host"], urlparse(expected_url).netloc)
示例#2
0
 def test_request_attributes(self):
     OpenTelemetryMiddleware._add_request_attributes(  # noqa pylint: disable=protected-access
         self.span, self.environ)
     expected = (
         mock.call("component", "http"),
         mock.call("http.method", "GET"),
         mock.call("http.host", "127.0.0.1"),
         mock.call("http.url", "http://127.0.0.1/"),
     )
     self.assertEqual(self.span.set_attribute.call_count, len(expected))
     self.span.set_attribute.assert_has_calls(expected, any_order=True)