def test_instrumentor(self): PyMySQLInstrumentor().instrument() cnx = pymysql.connect(database="test") cursor = cnx.cursor() query = "SELECT * FROM test" cursor.execute(query) spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) span = spans_list[0] # Check version and name in span's instrumentation info self.assertEqualSpanInstrumentationInfo( span, opentelemetry.instrumentation.pymysql) # check that no spans are generated after uninstrument PyMySQLInstrumentor().uninstrument() cnx = pymysql.connect(database="test") cursor = cnx.cursor() query = "SELECT * FROM test" cursor.execute(query) spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1)
def test_instrument_connection(self): cnx = pymysql.connect(database="test") query = "SELECT * FROM test" cursor = cnx.cursor() cursor.execute(query) spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 0) cnx = PyMySQLInstrumentor().instrument_connection(cnx) cursor = cnx.cursor() cursor.execute(query) spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1)
def setUp(self): super().setUp() self._tracer = self.tracer_provider.get_tracer(__name__) PyMySQLInstrumentor().instrument() self._connection = pymy.connect( user=MYSQL_USER, password=MYSQL_PASSWORD, host=MYSQL_HOST, port=MYSQL_PORT, database=MYSQL_DB_NAME, ) self._cursor = self._connection.cursor()
def test_custom_tracer_provider(self): resource = resources.Resource.create({}) result = self.create_tracer_provider(resource=resource) tracer_provider, exporter = result PyMySQLInstrumentor().instrument(tracer_provider=tracer_provider) cnx = pymysql.connect(database="test") cursor = cnx.cursor() query = "SELECT * FROM test" cursor.execute(query) spans_list = exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) span = spans_list[0] self.assertIs(span.resource, resource)
def tearDownClass(cls): if cls._connection: cls._connection.close() PyMySQLInstrumentor().uninstrument()
def tearDown(self): super().tearDown() with self.disable_logging(): PyMySQLInstrumentor().uninstrument()
def tearDown(self): self._cursor.close() self._connection.close() PyMySQLInstrumentor().uninstrument() super().tearDown()