Sync with sdk setup from setUpClass to setUp (#1193)
This commit is contained in:
		
							parent
							
								
									2ce69a668f
								
							
						
					
					
						commit
						d75194aed7
					
				|  | @ -6,7 +6,7 @@ on: | |||
|     - 'release/*' | ||||
|   pull_request: | ||||
| env: | ||||
|   CORE_REPO_SHA: 05d251c5d6baefe2f084e7361cb144c4fa10da96 | ||||
|   CORE_REPO_SHA: c09f2076a1878c6d58b78d3895485ef5559f30f7 | ||||
| 
 | ||||
| jobs: | ||||
|   build: | ||||
|  | @ -42,7 +42,7 @@ jobs: | |||
|           path: | | ||||
|             .tox | ||||
|             ~/.cache/pip | ||||
|           key: v6-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'gen-requirements.txt', 'dev-requirements.txt') }} | ||||
|           key: v7-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'gen-requirements.txt', 'dev-requirements.txt') }} | ||||
|       - name: run tox | ||||
|         run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- --benchmark-json=${{ env.RUN_MATRIX_COMBINATION }}-benchmark.json | ||||
|   #     - name: Find and merge ${{ matrix.package }} benchmarks | ||||
|  | @ -118,7 +118,7 @@ jobs: | |||
|           path: | | ||||
|             .tox | ||||
|             ~/.cache/pip | ||||
|           key: v6-misc-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt', 'gen-requirements.txt', 'docs-requirements.txt') }} | ||||
|           key: v7-misc-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt', 'gen-requirements.txt', 'docs-requirements.txt') }} | ||||
|       - name: run tox | ||||
|         run: tox -e ${{ matrix.tox-environment }} | ||||
|       - name: Ensure generated code is up to date | ||||
|  |  | |||
|  | @ -68,6 +68,7 @@ class MockConnection: | |||
| 
 | ||||
| class TestPostgresqlIntegration(TestBase): | ||||
|     def setUp(self): | ||||
|         super().setUp() | ||||
|         self.cursor_mock = mock.patch( | ||||
|             "opentelemetry.instrumentation.psycopg2.pg_cursor", MockCursor | ||||
|         ) | ||||
|  |  | |||
|  | @ -223,7 +223,6 @@ class PymongoInstrumentor(BaseInstrumentor): | |||
|         request_hook = kwargs.get("request_hook", dummy_callback) | ||||
|         response_hook = kwargs.get("response_hook", dummy_callback) | ||||
|         failed_hook = kwargs.get("failed_hook", dummy_callback) | ||||
| 
 | ||||
|         # Create and register a CommandTracer only the first time | ||||
|         if self._commandtracer_instance is None: | ||||
|             tracer = get_tracer(__name__, __version__, tracer_provider) | ||||
|  | @ -235,7 +234,6 @@ class PymongoInstrumentor(BaseInstrumentor): | |||
|                 failed_hook=failed_hook, | ||||
|             ) | ||||
|             monitoring.register(self._commandtracer_instance) | ||||
| 
 | ||||
|         # If already created, just enable it | ||||
|         self._commandtracer_instance.is_enabled = True | ||||
| 
 | ||||
|  |  | |||
|  | @ -21,9 +21,16 @@ from opentelemetry.trace import SpanKind | |||
| 
 | ||||
| 
 | ||||
| class TestRedis(TestBase): | ||||
|     def setUp(self): | ||||
|         super().setUp() | ||||
|         RedisInstrumentor().instrument(tracer_provider=self.tracer_provider) | ||||
| 
 | ||||
|     def tearDown(self): | ||||
|         super().tearDown() | ||||
|         RedisInstrumentor().uninstrument() | ||||
| 
 | ||||
|     def test_span_properties(self): | ||||
|         redis_client = redis.Redis() | ||||
|         RedisInstrumentor().instrument(tracer_provider=self.tracer_provider) | ||||
| 
 | ||||
|         with mock.patch.object(redis_client, "connection"): | ||||
|             redis_client.get("key") | ||||
|  | @ -36,7 +43,6 @@ class TestRedis(TestBase): | |||
| 
 | ||||
|     def test_not_recording(self): | ||||
|         redis_client = redis.Redis() | ||||
|         RedisInstrumentor().instrument(tracer_provider=self.tracer_provider) | ||||
| 
 | ||||
|         mock_tracer = mock.Mock() | ||||
|         mock_span = mock.Mock() | ||||
|  | @ -53,7 +59,6 @@ class TestRedis(TestBase): | |||
| 
 | ||||
|     def test_instrument_uninstrument(self): | ||||
|         redis_client = redis.Redis() | ||||
|         RedisInstrumentor().instrument(tracer_provider=self.tracer_provider) | ||||
| 
 | ||||
|         with mock.patch.object(redis_client, "connection"): | ||||
|             redis_client.get("key") | ||||
|  |  | |||
|  | @ -35,6 +35,10 @@ class TestRemouladeInstrumentation(TestBase): | |||
| 
 | ||||
|         broker.declare_actor(actor_div) | ||||
| 
 | ||||
|     def tearDown(self): | ||||
|         RemouladeInstrumentor().uninstrument() | ||||
|         super().tearDown() | ||||
| 
 | ||||
|     def test_message(self): | ||||
|         actor_div.send(2, 3) | ||||
| 
 | ||||
|  |  | |||
|  | @ -21,30 +21,26 @@ from opentelemetry.test.test_base import TestBase | |||
| 
 | ||||
| 
 | ||||
| class TestSQLite3(TestBase): | ||||
|     @classmethod | ||||
|     def setUpClass(cls): | ||||
|         super().setUpClass() | ||||
|         cls._connection = None | ||||
|         cls._cursor = None | ||||
|         cls._connection2 = None | ||||
|         cls._cursor2 = None | ||||
|         cls._tracer = cls.tracer_provider.get_tracer(__name__) | ||||
|         SQLite3Instrumentor().instrument(tracer_provider=cls.tracer_provider) | ||||
|         cls._connection = sqlite3.connect(":memory:") | ||||
|         cls._cursor = cls._connection.cursor() | ||||
|         cls._connection2 = dbapi2.connect(":memory:") | ||||
|         cls._cursor2 = cls._connection2.cursor() | ||||
|     def setUp(self): | ||||
|         super().setUp() | ||||
|         SQLite3Instrumentor().instrument(tracer_provider=self.tracer_provider) | ||||
|         self._tracer = self.tracer_provider.get_tracer(__name__) | ||||
|         self._connection = sqlite3.connect(":memory:") | ||||
|         self._cursor = self._connection.cursor() | ||||
|         self._connection2 = dbapi2.connect(":memory:") | ||||
|         self._cursor2 = self._connection2.cursor() | ||||
| 
 | ||||
|     @classmethod | ||||
|     def tearDownClass(cls): | ||||
|         if cls._cursor: | ||||
|             cls._cursor.close() | ||||
|         if cls._connection: | ||||
|             cls._connection.close() | ||||
|         if cls._cursor2: | ||||
|             cls._cursor2.close() | ||||
|         if cls._connection2: | ||||
|             cls._connection2.close() | ||||
|     def tearDown(self): | ||||
|         super().tearDown() | ||||
|         if self._cursor: | ||||
|             self._cursor.close() | ||||
|         if self._connection: | ||||
|             self._connection.close() | ||||
|         if self._cursor2: | ||||
|             self._cursor2.close() | ||||
|         if self._connection2: | ||||
|             self._connection2.close() | ||||
|         SQLite3Instrumentor().uninstrument() | ||||
| 
 | ||||
|     def validate_spans(self, span_name): | ||||
|         spans = self.memory_exporter.get_finished_spans() | ||||
|  | @ -65,6 +61,12 @@ class TestSQLite3(TestBase): | |||
|         self.assertIs(child_span.parent, root_span.get_span_context()) | ||||
|         self.assertIs(child_span.kind, trace_api.SpanKind.CLIENT) | ||||
| 
 | ||||
|     def _create_tables(self): | ||||
|         stmt = "CREATE TABLE IF NOT EXISTS test (id integer)" | ||||
|         self._cursor.execute(stmt) | ||||
|         self._cursor2.execute(stmt) | ||||
|         self.memory_exporter.clear() | ||||
| 
 | ||||
|     def test_execute(self): | ||||
|         """Should create a child span for execute method""" | ||||
|         stmt = "CREATE TABLE IF NOT EXISTS test (id integer)" | ||||
|  | @ -78,6 +80,9 @@ class TestSQLite3(TestBase): | |||
| 
 | ||||
|     def test_executemany(self): | ||||
|         """Should create a child span for executemany""" | ||||
|         self._create_tables() | ||||
| 
 | ||||
|         # real spans for executemany | ||||
|         stmt = "INSERT INTO test (id) VALUES (?)" | ||||
|         data = [("1",), ("2",), ("3",)] | ||||
|         with self._tracer.start_as_current_span("rootSpan"): | ||||
|  |  | |||
|  | @ -508,8 +508,7 @@ class TestWsgiMiddlewareWrappedWithAnotherFramework(WsgiTestBase): | |||
| class TestAdditionOfCustomRequestResponseHeaders(WsgiTestBase): | ||||
|     def setUp(self): | ||||
|         super().setUp() | ||||
|         tracer_provider, _ = TestBase.create_tracer_provider() | ||||
|         self.tracer = tracer_provider.get_tracer(__name__) | ||||
|         self.tracer = self.tracer_provider.get_tracer(__name__) | ||||
| 
 | ||||
|     def iterate_response(self, response): | ||||
|         while True: | ||||
|  |  | |||
|  | @ -26,9 +26,6 @@ from opentelemetry.test.test_base import TestBase | |||
| 
 | ||||
| 
 | ||||
| class TestDependencyConflicts(TestBase): | ||||
|     def setUp(self): | ||||
|         pass | ||||
| 
 | ||||
|     def test_get_dependency_conflicts_empty(self): | ||||
|         self.assertIsNone(get_dependency_conflicts([])) | ||||
| 
 | ||||
|  |  | |||
|  | @ -14,6 +14,8 @@ | |||
| 
 | ||||
| # pylint: disable=protected-access | ||||
| 
 | ||||
| import unittest | ||||
| 
 | ||||
| from opentelemetry import trace | ||||
| from opentelemetry.instrumentation import propagators | ||||
| from opentelemetry.instrumentation.propagators import ( | ||||
|  | @ -39,7 +41,7 @@ class TestGlobals(TestBase): | |||
|         propagators._RESPONSE_PROPAGATOR = original | ||||
| 
 | ||||
| 
 | ||||
| class TestDictHeaderSetter(TestBase): | ||||
| class TestDictHeaderSetter(unittest.TestCase): | ||||
|     def test_simple(self): | ||||
|         setter = DictHeaderSetter() | ||||
|         carrier = {} | ||||
|  |  | |||
|  | @ -12,17 +12,17 @@ | |||
| # See the License for the specific language governing permissions and | ||||
| # limitations under the License. | ||||
| 
 | ||||
| import unittest | ||||
| from http import HTTPStatus | ||||
| 
 | ||||
| from opentelemetry.instrumentation.utils import ( | ||||
|     _python_path_without_directory, | ||||
|     http_status_to_status_code, | ||||
| ) | ||||
| from opentelemetry.test.test_base import TestBase | ||||
| from opentelemetry.trace import StatusCode | ||||
| 
 | ||||
| 
 | ||||
| class TestUtils(TestBase): | ||||
| class TestUtils(unittest.TestCase): | ||||
|     # See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#status | ||||
|     def test_http_status_to_status_code(self): | ||||
|         for status_code, expected in ( | ||||
|  |  | |||
|  | @ -21,14 +21,11 @@ def async_call(coro): | |||
| 
 | ||||
| 
 | ||||
| class TestFunctionalAsyncPG(TestBase): | ||||
|     @classmethod | ||||
|     def setUpClass(cls): | ||||
|         super().setUpClass() | ||||
|         cls._connection = None | ||||
|         cls._cursor = None | ||||
|         cls._tracer = cls.tracer_provider.get_tracer(__name__) | ||||
|         AsyncPGInstrumentor().instrument(tracer_provider=cls.tracer_provider) | ||||
|         cls._connection = async_call( | ||||
|     def setUp(self): | ||||
|         super().setUp() | ||||
|         self._tracer = self.tracer_provider.get_tracer(__name__) | ||||
|         AsyncPGInstrumentor().instrument(tracer_provider=self.tracer_provider) | ||||
|         self._connection = async_call( | ||||
|             asyncpg.connect( | ||||
|                 database=POSTGRES_DB_NAME, | ||||
|                 user=POSTGRES_USER, | ||||
|  | @ -38,9 +35,9 @@ class TestFunctionalAsyncPG(TestBase): | |||
|             ) | ||||
|         ) | ||||
| 
 | ||||
|     @classmethod | ||||
|     def tearDownClass(cls): | ||||
|     def tearDown(self): | ||||
|         AsyncPGInstrumentor().uninstrument() | ||||
|         super().tearDown() | ||||
| 
 | ||||
|     def check_span(self, span): | ||||
|         self.assertEqual( | ||||
|  | @ -148,16 +145,13 @@ class TestFunctionalAsyncPG(TestBase): | |||
| 
 | ||||
| 
 | ||||
| class TestFunctionalAsyncPG_CaptureParameters(TestBase): | ||||
|     @classmethod | ||||
|     def setUpClass(cls): | ||||
|         super().setUpClass() | ||||
|         cls._connection = None | ||||
|         cls._cursor = None | ||||
|         cls._tracer = cls.tracer_provider.get_tracer(__name__) | ||||
|     def setUp(self): | ||||
|         super().setUp() | ||||
|         self._tracer = self.tracer_provider.get_tracer(__name__) | ||||
|         AsyncPGInstrumentor(capture_parameters=True).instrument( | ||||
|             tracer_provider=cls.tracer_provider | ||||
|             tracer_provider=self.tracer_provider | ||||
|         ) | ||||
|         cls._connection = async_call( | ||||
|         self._connection = async_call( | ||||
|             asyncpg.connect( | ||||
|                 database=POSTGRES_DB_NAME, | ||||
|                 user=POSTGRES_USER, | ||||
|  | @ -167,9 +161,9 @@ class TestFunctionalAsyncPG_CaptureParameters(TestBase): | |||
|             ) | ||||
|         ) | ||||
| 
 | ||||
|     @classmethod | ||||
|     def tearDownClass(cls): | ||||
|     def tearDown(self): | ||||
|         AsyncPGInstrumentor().uninstrument() | ||||
|         super().tearDown() | ||||
| 
 | ||||
|     def check_span(self, span): | ||||
|         self.assertEqual( | ||||
|  |  | |||
|  | @ -29,22 +29,10 @@ MYSQL_DB_NAME = os.getenv("MYSQL_DB_NAME", "opentelemetry-tests") | |||
| 
 | ||||
| 
 | ||||
| class TestFunctionalMysql(TestBase): | ||||
|     @classmethod | ||||
|     def setUpClass(cls): | ||||
|         super().setUpClass() | ||||
|         cls._connection = None | ||||
|         cls._cursor = None | ||||
|         cls._tracer = cls.tracer_provider.get_tracer(__name__) | ||||
|         MySQLInstrumentor().instrument() | ||||
| 
 | ||||
|     @classmethod | ||||
|     def tearDownClass(cls): | ||||
|         if cls._connection: | ||||
|             cls._connection.close() | ||||
|         MySQLInstrumentor().uninstrument() | ||||
| 
 | ||||
|     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, | ||||
|  | @ -54,6 +42,12 @@ class TestFunctionalMysql(TestBase): | |||
|         ) | ||||
|         self._cursor = self._connection.cursor() | ||||
| 
 | ||||
|     def tearDown(self): | ||||
|         self._cursor.close() | ||||
|         self._connection.close() | ||||
|         MySQLInstrumentor().uninstrument() | ||||
|         super().tearDown() | ||||
| 
 | ||||
|     def validate_spans(self, span_name): | ||||
|         spans = self.memory_exporter.get_finished_spans() | ||||
|         self.assertEqual(len(spans), 2) | ||||
|  |  | |||
|  | @ -36,14 +36,11 @@ def async_call(coro): | |||
| 
 | ||||
| 
 | ||||
| class TestFunctionalAiopgConnect(TestBase): | ||||
|     @classmethod | ||||
|     def setUpClass(cls): | ||||
|         super().setUpClass() | ||||
|         cls._connection = None | ||||
|         cls._cursor = None | ||||
|         cls._tracer = cls.tracer_provider.get_tracer(__name__) | ||||
|         AiopgInstrumentor().instrument(tracer_provider=cls.tracer_provider) | ||||
|         cls._connection = async_call( | ||||
|     def setUp(self): | ||||
|         super().setUp() | ||||
|         self._tracer = self.tracer_provider.get_tracer(__name__) | ||||
|         AiopgInstrumentor().instrument(tracer_provider=self.tracer_provider) | ||||
|         self._connection = async_call( | ||||
|             aiopg.connect( | ||||
|                 dbname=POSTGRES_DB_NAME, | ||||
|                 user=POSTGRES_USER, | ||||
|  | @ -52,15 +49,13 @@ class TestFunctionalAiopgConnect(TestBase): | |||
|                 port=POSTGRES_PORT, | ||||
|             ) | ||||
|         ) | ||||
|         cls._cursor = async_call(cls._connection.cursor()) | ||||
|         self._cursor = async_call(self._connection.cursor()) | ||||
| 
 | ||||
|     @classmethod | ||||
|     def tearDownClass(cls): | ||||
|         if cls._cursor: | ||||
|             cls._cursor.close() | ||||
|         if cls._connection: | ||||
|             cls._connection.close() | ||||
|     def tearDown(self): | ||||
|         self._cursor.close() | ||||
|         self._connection.close() | ||||
|         AiopgInstrumentor().uninstrument() | ||||
|         super().tearDown() | ||||
| 
 | ||||
|     def validate_spans(self, span_name): | ||||
|         spans = self.memory_exporter.get_finished_spans() | ||||
|  | @ -121,18 +116,15 @@ class TestFunctionalAiopgConnect(TestBase): | |||
| 
 | ||||
| 
 | ||||
| class TestFunctionalAiopgCreatePool(TestBase): | ||||
|     @classmethod | ||||
|     def setUpClass(cls): | ||||
|         super().setUpClass() | ||||
|         cls._connection = None | ||||
|         cls._cursor = None | ||||
|         cls._tracer = cls.tracer_provider.get_tracer(__name__) | ||||
|         AiopgInstrumentor().instrument(tracer_provider=cls.tracer_provider) | ||||
|         cls._dsn = ( | ||||
|     def setUp(self): | ||||
|         super().setUp() | ||||
|         self._tracer = self.tracer_provider.get_tracer(__name__) | ||||
|         AiopgInstrumentor().instrument(tracer_provider=self.tracer_provider) | ||||
|         self._dsn = ( | ||||
|             f"dbname='{POSTGRES_DB_NAME}' user='{POSTGRES_USER}' password='{POSTGRES_PASSWORD}'" | ||||
|             f" host='{POSTGRES_HOST}' port='{POSTGRES_PORT}'" | ||||
|         ) | ||||
|         cls._pool = async_call( | ||||
|         self._pool = async_call( | ||||
|             aiopg.create_pool( | ||||
|                 dbname=POSTGRES_DB_NAME, | ||||
|                 user=POSTGRES_USER, | ||||
|  | @ -141,18 +133,15 @@ class TestFunctionalAiopgCreatePool(TestBase): | |||
|                 port=POSTGRES_PORT, | ||||
|             ) | ||||
|         ) | ||||
|         cls._connection = async_call(cls._pool.acquire()) | ||||
|         cls._cursor = async_call(cls._connection.cursor()) | ||||
|         self._connection = async_call(self._pool.acquire()) | ||||
|         self._cursor = async_call(self._connection.cursor()) | ||||
| 
 | ||||
|     @classmethod | ||||
|     def tearDownClass(cls): | ||||
|         if cls._cursor: | ||||
|             cls._cursor.close() | ||||
|         if cls._connection: | ||||
|             cls._connection.close() | ||||
|         if cls._pool: | ||||
|             cls._pool.close() | ||||
|     def tearDown(self): | ||||
|         self._cursor.close() | ||||
|         self._connection.close() | ||||
|         self._pool.close() | ||||
|         AiopgInstrumentor().uninstrument() | ||||
|         super().tearDown() | ||||
| 
 | ||||
|     def validate_spans(self, span_name): | ||||
|         spans = self.memory_exporter.get_finished_spans() | ||||
|  |  | |||
|  | @ -30,30 +30,25 @@ POSTGRES_USER = os.getenv("POSTGRESQL_USER", "testuser") | |||
| 
 | ||||
| 
 | ||||
| class TestFunctionalPsycopg(TestBase): | ||||
|     @classmethod | ||||
|     def setUpClass(cls): | ||||
|         super().setUpClass() | ||||
|         cls._connection = None | ||||
|         cls._cursor = None | ||||
|         cls._tracer = cls.tracer_provider.get_tracer(__name__) | ||||
|         Psycopg2Instrumentor().instrument(tracer_provider=cls.tracer_provider) | ||||
|         cls._connection = psycopg2.connect( | ||||
|     def setUp(self): | ||||
|         super().setUp() | ||||
|         self._tracer = self.tracer_provider.get_tracer(__name__) | ||||
|         Psycopg2Instrumentor().instrument(tracer_provider=self.tracer_provider) | ||||
|         self._connection = psycopg2.connect( | ||||
|             dbname=POSTGRES_DB_NAME, | ||||
|             user=POSTGRES_USER, | ||||
|             password=POSTGRES_PASSWORD, | ||||
|             host=POSTGRES_HOST, | ||||
|             port=POSTGRES_PORT, | ||||
|         ) | ||||
|         cls._connection.set_session(autocommit=True) | ||||
|         cls._cursor = cls._connection.cursor() | ||||
|         self._connection.set_session(autocommit=True) | ||||
|         self._cursor = self._connection.cursor() | ||||
| 
 | ||||
|     @classmethod | ||||
|     def tearDownClass(cls): | ||||
|         if cls._cursor: | ||||
|             cls._cursor.close() | ||||
|         if cls._connection: | ||||
|             cls._connection.close() | ||||
|     def tearDown(self): | ||||
|         self._cursor.close() | ||||
|         self._connection.close() | ||||
|         Psycopg2Instrumentor().uninstrument() | ||||
|         super().tearDown() | ||||
| 
 | ||||
|     def validate_spans(self, span_name): | ||||
|         spans = self.memory_exporter.get_finished_spans() | ||||
|  |  | |||
|  | @ -26,30 +26,25 @@ from opentelemetry.test.test_base import TestBase | |||
| 
 | ||||
| 
 | ||||
| class TestFunctionalPsycopg(TestBase): | ||||
|     @classmethod | ||||
|     def setUpClass(cls): | ||||
|         super().setUpClass() | ||||
|         cls._connection = None | ||||
|         cls._cursor = None | ||||
|         cls._tracer = cls.tracer_provider.get_tracer(__name__) | ||||
|     def setUp(self): | ||||
|         super().setUp() | ||||
|         self._tracer = self.tracer_provider.get_tracer(__name__) | ||||
|         Psycopg2Instrumentor().instrument(enable_commenter=True) | ||||
|         cls._connection = psycopg2.connect( | ||||
|         self._connection = psycopg2.connect( | ||||
|             dbname=POSTGRES_DB_NAME, | ||||
|             user=POSTGRES_USER, | ||||
|             password=POSTGRES_PASSWORD, | ||||
|             host=POSTGRES_HOST, | ||||
|             port=POSTGRES_PORT, | ||||
|         ) | ||||
|         cls._connection.set_session(autocommit=True) | ||||
|         cls._cursor = cls._connection.cursor() | ||||
|         self._connection.set_session(autocommit=True) | ||||
|         self._cursor = self._connection.cursor() | ||||
| 
 | ||||
|     @classmethod | ||||
|     def tearDownClass(cls): | ||||
|         if cls._cursor: | ||||
|             cls._cursor.close() | ||||
|         if cls._connection: | ||||
|             cls._connection.close() | ||||
|     def tearDown(self): | ||||
|         self._cursor.close() | ||||
|         self._connection.close() | ||||
|         Psycopg2Instrumentor().uninstrument() | ||||
|         super().tearDown() | ||||
| 
 | ||||
|     def test_commenter_enabled(self): | ||||
|         self._cursor.execute("SELECT  1;") | ||||
|  |  | |||
|  | @ -28,16 +28,21 @@ MONGODB_COLLECTION_NAME = "test" | |||
| 
 | ||||
| 
 | ||||
| class TestFunctionalPymongo(TestBase): | ||||
|     @classmethod | ||||
|     def setUpClass(cls): | ||||
|         super().setUpClass() | ||||
|         cls._tracer = cls.tracer_provider.get_tracer(__name__) | ||||
|         PymongoInstrumentor().instrument() | ||||
|     def setUp(self): | ||||
|         super().setUp() | ||||
|         self._tracer = self.tracer_provider.get_tracer(__name__) | ||||
|         self.instrumentor = PymongoInstrumentor() | ||||
|         self.instrumentor.instrument() | ||||
|         self.instrumentor._commandtracer_instance._tracer = self._tracer | ||||
|         client = MongoClient( | ||||
|             MONGODB_HOST, MONGODB_PORT, serverSelectionTimeoutMS=2000 | ||||
|         ) | ||||
|         db = client[MONGODB_DB_NAME] | ||||
|         cls._collection = db[MONGODB_COLLECTION_NAME] | ||||
|         self._collection = db[MONGODB_COLLECTION_NAME] | ||||
| 
 | ||||
|     def tearDown(self): | ||||
|         self.instrumentor.uninstrument() | ||||
|         super().tearDown() | ||||
| 
 | ||||
|     def validate_spans(self): | ||||
|         spans = self.memory_exporter.get_finished_spans() | ||||
|  |  | |||
|  | @ -29,27 +29,24 @@ MYSQL_DB_NAME = os.getenv("MYSQL_DB_NAME", "opentelemetry-tests") | |||
| 
 | ||||
| 
 | ||||
| class TestFunctionalPyMysql(TestBase): | ||||
|     @classmethod | ||||
|     def setUpClass(cls): | ||||
|         super().setUpClass() | ||||
|         cls._connection = None | ||||
|         cls._cursor = None | ||||
|         cls._tracer = cls.tracer_provider.get_tracer(__name__) | ||||
|     def setUp(self): | ||||
|         super().setUp() | ||||
|         self._tracer = self.tracer_provider.get_tracer(__name__) | ||||
|         PyMySQLInstrumentor().instrument() | ||||
|         cls._connection = pymy.connect( | ||||
|         self._connection = pymy.connect( | ||||
|             user=MYSQL_USER, | ||||
|             password=MYSQL_PASSWORD, | ||||
|             host=MYSQL_HOST, | ||||
|             port=MYSQL_PORT, | ||||
|             database=MYSQL_DB_NAME, | ||||
|         ) | ||||
|         cls._cursor = cls._connection.cursor() | ||||
|         self._cursor = self._connection.cursor() | ||||
| 
 | ||||
|     @classmethod | ||||
|     def tearDownClass(cls): | ||||
|         if cls._connection: | ||||
|             cls._connection.close() | ||||
|     def tearDown(self): | ||||
|         self._cursor.close() | ||||
|         self._connection.close() | ||||
|         PyMySQLInstrumentor().uninstrument() | ||||
|         super().tearDown() | ||||
| 
 | ||||
|     def validate_spans(self, span_name): | ||||
|         spans = self.memory_exporter.get_finished_spans() | ||||
|  |  | |||
|  | @ -31,8 +31,8 @@ class TestRedisInstrument(TestBase): | |||
|         RedisInstrumentor().instrument(tracer_provider=self.tracer_provider) | ||||
| 
 | ||||
|     def tearDown(self): | ||||
|         super().tearDown() | ||||
|         RedisInstrumentor().uninstrument() | ||||
|         super().tearDown() | ||||
| 
 | ||||
|     def _check_span(self, span, name): | ||||
|         self.assertEqual(span.name, name) | ||||
|  | @ -203,8 +203,8 @@ class TestAsyncRedisInstrument(TestBase): | |||
|         RedisInstrumentor().instrument(tracer_provider=self.tracer_provider) | ||||
| 
 | ||||
|     def tearDown(self): | ||||
|         super().tearDown() | ||||
|         RedisInstrumentor().uninstrument() | ||||
|         super().tearDown() | ||||
| 
 | ||||
|     def _check_span(self, span, name): | ||||
|         self.assertEqual(span.name, name) | ||||
|  | @ -383,8 +383,8 @@ class TestRedisDBIndexInstrument(TestBase): | |||
|         RedisInstrumentor().instrument(tracer_provider=self.tracer_provider) | ||||
| 
 | ||||
|     def tearDown(self): | ||||
|         super().tearDown() | ||||
|         RedisInstrumentor().uninstrument() | ||||
|         super().tearDown() | ||||
| 
 | ||||
|     def _check_span(self, span, name): | ||||
|         self.assertEqual(span.name, name) | ||||
|  |  | |||
|  | @ -35,6 +35,7 @@ class SQLAlchemyInstrumentTestCase(TestBase): | |||
|     """ | ||||
| 
 | ||||
|     def setUp(self): | ||||
|         super().setUp() | ||||
|         # create a traced engine with the given arguments | ||||
|         SQLAlchemyInstrumentor().instrument() | ||||
|         dsn = ( | ||||
|  | @ -45,23 +46,23 @@ class SQLAlchemyInstrumentTestCase(TestBase): | |||
| 
 | ||||
|         # prepare a connection | ||||
|         self.conn = self.engine.connect() | ||||
|         super().setUp() | ||||
| 
 | ||||
|     def tearDown(self): | ||||
|         # clear the database and dispose the engine | ||||
|         self.conn.close() | ||||
|         self.engine.dispose() | ||||
|         SQLAlchemyInstrumentor().uninstrument() | ||||
|         super().tearDown() | ||||
| 
 | ||||
|     def test_engine_traced(self): | ||||
|         # ensures that the engine is traced | ||||
|         rows = self.conn.execute("SELECT").fetchall() | ||||
|         self.assertEqual(len(rows), 1) | ||||
| 
 | ||||
|         traces = self.memory_exporter.get_finished_spans() | ||||
|         spans = self.memory_exporter.get_finished_spans() | ||||
|         # trace composition | ||||
|         self.assertEqual(len(traces), 1) | ||||
|         span = traces[0] | ||||
|         self.assertEqual(len(spans), 2) | ||||
|         span = spans[1] | ||||
|         # check subset of span fields | ||||
|         self.assertEqual(span.name, "SELECT opentelemetry-tests") | ||||
|         self.assertIs(span.status.status_code, trace.StatusCode.UNSET) | ||||
|  |  | |||
|  | @ -12,9 +12,9 @@ | |||
| # See the License for the specific language governing permissions and | ||||
| # limitations under the License. | ||||
| 
 | ||||
| import unittest | ||||
| from unittest.mock import patch | ||||
| 
 | ||||
| from opentelemetry.test.test_base import TestBase | ||||
| from opentelemetry.util.http import ( | ||||
|     OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST, | ||||
|     OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE, | ||||
|  | @ -24,7 +24,7 @@ from opentelemetry.util.http import ( | |||
| ) | ||||
| 
 | ||||
| 
 | ||||
| class TestCaptureCustomHeaders(TestBase): | ||||
| class TestCaptureCustomHeaders(unittest.TestCase): | ||||
|     @patch.dict( | ||||
|         "os.environ", | ||||
|         { | ||||
|  |  | |||
|  | @ -12,13 +12,13 @@ | |||
| # See the License for the specific language governing permissions and | ||||
| # limitations under the License. | ||||
| 
 | ||||
| import unittest | ||||
| from unittest.mock import patch | ||||
| 
 | ||||
| from opentelemetry.test.test_base import TestBase | ||||
| from opentelemetry.util.http import get_excluded_urls | ||||
| 
 | ||||
| 
 | ||||
| class TestGetExcludedUrls(TestBase): | ||||
| class TestGetExcludedUrls(unittest.TestCase): | ||||
|     @patch.dict( | ||||
|         "os.environ", | ||||
|         { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue