def test_instrumentor(self, mock_connect): MySQLInstrumentor().instrument() cnx = mysql.connector.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.check_span_instrumentation_info( span, opentelemetry.instrumentation.mysql) # check that no spans are generated after uninstrumen MySQLInstrumentor().uninstrument() cnx = mysql.connector.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, mock_connect): cnx = mysql.connector.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 = MySQLInstrumentor().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__) MySQLInstrumentor().instrument() self._connection = mysql.connector.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, mock_connect): resource = resources.Resource.create({}) result = self.create_tracer_provider(resource=resource) tracer_provider, exporter = result MySQLInstrumentor().instrument(tracer_provider=tracer_provider) cnx = mysql.connector.connect(database="test") cursor = cnx.cursor() query = "SELECT * FROM test" cursor.execute(query) span_list = exporter.get_finished_spans() self.assertEqual(len(span_list), 1) span = span_list[0] self.assertIs(span.resource, resource)
def tearDownClass(cls): if cls._connection: cls._connection.close() MySQLInstrumentor().uninstrument()
def setUpClass(cls): super().setUpClass() cls._connection = None cls._cursor = None cls._tracer = cls.tracer_provider.get_tracer(__name__) MySQLInstrumentor().instrument()
) ) # configure exporter to Jaeger jaeger_exporter = thrift.JaegerExporter( agent_host_name="localhost", agent_port=6831, ) trace.get_tracer_provider().add_span_processor( BatchSpanProcessor(jaeger_exporter) ) # Enable instrumentation for Flask and MySQL libraries FlaskInstrumentor().instrument() MySQLInstrumentor().instrument() tracer = trace.get_tracer(__name__) ############################# application code ################################# app = flask.Flask(__name__) mydb = mysql.connector.connect( user=MYSQL_USER, password=MYSQL_PASSWORD, host=MYSQL_HOST, port=MYSQL_PORT, database=MYSQL_DB_NAME, ) mycursor = mydb.cursor()
def tearDown(self): super().tearDown() with self.disable_logging(): MySQLInstrumentor().uninstrument()
def tearDown(self): self._cursor.close() self._connection.close() MySQLInstrumentor().uninstrument() super().tearDown()