def setUp(self): super().setUp() config = Configurator() PyramidInstrumentor().instrument_config(config) self.config = config self._common_initialization(self.config)
def test_tween_list(self): tween_list = "opentelemetry.instrumentation.pyramid.trace_tween_factory\npyramid.tweens.excview_tween_factory" config = Configurator(settings={"pyramid.tweens": tween_list}) PyramidInstrumentor().instrument_config(config) self._common_initialization(config) resp = self.client.get("/hello/123") self.assertEqual(200, resp.status_code) self.assertEqual([b"Hello: 123"], list(resp.response)) span_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(span_list), 1) PyramidInstrumentor().uninstrument_config(config) # Need to remake the WSGI app export self._common_initialization(config) resp = self.client.get("/hello/123") self.assertEqual(200, resp.status_code) self.assertEqual([b"Hello: 123"], list(resp.response)) span_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(span_list), 1)
def test_uninstrument(self): resp = self.client.get("/hello/123") self.assertEqual(200, resp.status_code) self.assertEqual([b"Hello: 123"], list(resp.response)) span_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(span_list), 1) PyramidInstrumentor().uninstrument_config(self.config) # Need to remake the WSGI app export self._common_initialization(self.config) resp = self.client.get("/hello/123") self.assertEqual(200, resp.status_code) self.assertEqual([b"Hello: 123"], list(resp.response)) span_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(span_list), 1)
def test_uninstrument(self): # pylint: disable=access-member-before-definition resp = self.client.get("/hello/123") self.assertEqual(200, resp.status_code) self.assertEqual([b"Hello: 123"], list(resp.response)) span_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(span_list), 1) PyramidInstrumentor().uninstrument() self.config = Configurator() self._common_initialization(self.config) resp = self.client.get("/hello/123") self.assertEqual(200, resp.status_code) self.assertEqual([b"Hello: 123"], list(resp.response)) span_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(span_list), 1)
def setUp(self): super().setUp() config = Configurator() PyramidInstrumentor().instrument_config(config) self.config = config self._common_initialization(self.config) self.env_patch = patch.dict( "os.environ", { "OTEL_PYTHON_PYRAMID_EXCLUDED_URLS": "http://localhost/excluded_arg/123,excluded_noarg" }, ) self.env_patch.start() self.exclude_patch = patch( "opentelemetry.instrumentation.pyramid.callbacks._excluded_urls", get_excluded_urls("PYRAMID"), ) self.exclude_patch.start()
def test_warnings(self, mock_logger): tween_list = "pyramid.tweens.excview_tween_factory" config = Configurator(settings={"pyramid.tweens": tween_list}) PyramidInstrumentor().instrument_config(config) self._common_initialization(config) self.client.get("/hello/123") span_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(span_list), 0) self.assertEqual(mock_logger.warning.called, True) mock_logger.warning.called = False tween_list = ( "opentelemetry.instrumentation.pyramid.trace_tween_factory") config = Configurator(settings={"pyramid.tweens": tween_list}) self._common_initialization(config) self.client.get("/hello/123") span_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(span_list), 0) self.assertEqual(mock_logger.warning.called, True)
def tearDown(self): super().tearDown() with self.disable_logging(): PyramidInstrumentor().uninstrument_config(self.config)