コード例 #1
0
    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)
コード例 #2
0
    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)
コード例 #3
0
 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()
コード例 #4
0
    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)
コード例 #5
0
 def tearDownClass(cls):
     if cls._connection:
         cls._connection.close()
     PyMySQLInstrumentor().uninstrument()
コード例 #6
0
 def tearDown(self):
     super().tearDown()
     with self.disable_logging():
         PyMySQLInstrumentor().uninstrument()
コード例 #7
0
 def tearDown(self):
     self._cursor.close()
     self._connection.close()
     PyMySQLInstrumentor().uninstrument()
     super().tearDown()