Sync with sdk setup from setUpClass to setUp (#1193)

This commit is contained in:
Srikanth Chekuri 2022-07-19 02:02:13 +05:30 committed by GitHub
parent 2ce69a668f
commit d75194aed7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 148 additions and 167 deletions

View File

@ -6,7 +6,7 @@ on:
- 'release/*' - 'release/*'
pull_request: pull_request:
env: env:
CORE_REPO_SHA: 05d251c5d6baefe2f084e7361cb144c4fa10da96 CORE_REPO_SHA: c09f2076a1878c6d58b78d3895485ef5559f30f7
jobs: jobs:
build: build:
@ -42,7 +42,7 @@ jobs:
path: | path: |
.tox .tox
~/.cache/pip ~/.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 - name: run tox
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- --benchmark-json=${{ env.RUN_MATRIX_COMBINATION }}-benchmark.json run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- --benchmark-json=${{ env.RUN_MATRIX_COMBINATION }}-benchmark.json
# - name: Find and merge ${{ matrix.package }} benchmarks # - name: Find and merge ${{ matrix.package }} benchmarks
@ -118,7 +118,7 @@ jobs:
path: | path: |
.tox .tox
~/.cache/pip ~/.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 - name: run tox
run: tox -e ${{ matrix.tox-environment }} run: tox -e ${{ matrix.tox-environment }}
- name: Ensure generated code is up to date - name: Ensure generated code is up to date

View File

@ -68,6 +68,7 @@ class MockConnection:
class TestPostgresqlIntegration(TestBase): class TestPostgresqlIntegration(TestBase):
def setUp(self): def setUp(self):
super().setUp()
self.cursor_mock = mock.patch( self.cursor_mock = mock.patch(
"opentelemetry.instrumentation.psycopg2.pg_cursor", MockCursor "opentelemetry.instrumentation.psycopg2.pg_cursor", MockCursor
) )

View File

@ -223,7 +223,6 @@ class PymongoInstrumentor(BaseInstrumentor):
request_hook = kwargs.get("request_hook", dummy_callback) request_hook = kwargs.get("request_hook", dummy_callback)
response_hook = kwargs.get("response_hook", dummy_callback) response_hook = kwargs.get("response_hook", dummy_callback)
failed_hook = kwargs.get("failed_hook", dummy_callback) failed_hook = kwargs.get("failed_hook", dummy_callback)
# Create and register a CommandTracer only the first time # Create and register a CommandTracer only the first time
if self._commandtracer_instance is None: if self._commandtracer_instance is None:
tracer = get_tracer(__name__, __version__, tracer_provider) tracer = get_tracer(__name__, __version__, tracer_provider)
@ -235,7 +234,6 @@ class PymongoInstrumentor(BaseInstrumentor):
failed_hook=failed_hook, failed_hook=failed_hook,
) )
monitoring.register(self._commandtracer_instance) monitoring.register(self._commandtracer_instance)
# If already created, just enable it # If already created, just enable it
self._commandtracer_instance.is_enabled = True self._commandtracer_instance.is_enabled = True

View File

@ -21,9 +21,16 @@ from opentelemetry.trace import SpanKind
class TestRedis(TestBase): 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): def test_span_properties(self):
redis_client = redis.Redis() redis_client = redis.Redis()
RedisInstrumentor().instrument(tracer_provider=self.tracer_provider)
with mock.patch.object(redis_client, "connection"): with mock.patch.object(redis_client, "connection"):
redis_client.get("key") redis_client.get("key")
@ -36,7 +43,6 @@ class TestRedis(TestBase):
def test_not_recording(self): def test_not_recording(self):
redis_client = redis.Redis() redis_client = redis.Redis()
RedisInstrumentor().instrument(tracer_provider=self.tracer_provider)
mock_tracer = mock.Mock() mock_tracer = mock.Mock()
mock_span = mock.Mock() mock_span = mock.Mock()
@ -53,7 +59,6 @@ class TestRedis(TestBase):
def test_instrument_uninstrument(self): def test_instrument_uninstrument(self):
redis_client = redis.Redis() redis_client = redis.Redis()
RedisInstrumentor().instrument(tracer_provider=self.tracer_provider)
with mock.patch.object(redis_client, "connection"): with mock.patch.object(redis_client, "connection"):
redis_client.get("key") redis_client.get("key")

View File

@ -35,6 +35,10 @@ class TestRemouladeInstrumentation(TestBase):
broker.declare_actor(actor_div) broker.declare_actor(actor_div)
def tearDown(self):
RemouladeInstrumentor().uninstrument()
super().tearDown()
def test_message(self): def test_message(self):
actor_div.send(2, 3) actor_div.send(2, 3)

View File

@ -21,30 +21,26 @@ from opentelemetry.test.test_base import TestBase
class TestSQLite3(TestBase): class TestSQLite3(TestBase):
@classmethod def setUp(self):
def setUpClass(cls): super().setUp()
super().setUpClass() SQLite3Instrumentor().instrument(tracer_provider=self.tracer_provider)
cls._connection = None self._tracer = self.tracer_provider.get_tracer(__name__)
cls._cursor = None self._connection = sqlite3.connect(":memory:")
cls._connection2 = None self._cursor = self._connection.cursor()
cls._cursor2 = None self._connection2 = dbapi2.connect(":memory:")
cls._tracer = cls.tracer_provider.get_tracer(__name__) self._cursor2 = self._connection2.cursor()
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()
@classmethod def tearDown(self):
def tearDownClass(cls): super().tearDown()
if cls._cursor: if self._cursor:
cls._cursor.close() self._cursor.close()
if cls._connection: if self._connection:
cls._connection.close() self._connection.close()
if cls._cursor2: if self._cursor2:
cls._cursor2.close() self._cursor2.close()
if cls._connection2: if self._connection2:
cls._connection2.close() self._connection2.close()
SQLite3Instrumentor().uninstrument()
def validate_spans(self, span_name): def validate_spans(self, span_name):
spans = self.memory_exporter.get_finished_spans() 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.parent, root_span.get_span_context())
self.assertIs(child_span.kind, trace_api.SpanKind.CLIENT) 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): def test_execute(self):
"""Should create a child span for execute method""" """Should create a child span for execute method"""
stmt = "CREATE TABLE IF NOT EXISTS test (id integer)" stmt = "CREATE TABLE IF NOT EXISTS test (id integer)"
@ -78,6 +80,9 @@ class TestSQLite3(TestBase):
def test_executemany(self): def test_executemany(self):
"""Should create a child span for executemany""" """Should create a child span for executemany"""
self._create_tables()
# real spans for executemany
stmt = "INSERT INTO test (id) VALUES (?)" stmt = "INSERT INTO test (id) VALUES (?)"
data = [("1",), ("2",), ("3",)] data = [("1",), ("2",), ("3",)]
with self._tracer.start_as_current_span("rootSpan"): with self._tracer.start_as_current_span("rootSpan"):

View File

@ -508,8 +508,7 @@ class TestWsgiMiddlewareWrappedWithAnotherFramework(WsgiTestBase):
class TestAdditionOfCustomRequestResponseHeaders(WsgiTestBase): class TestAdditionOfCustomRequestResponseHeaders(WsgiTestBase):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
tracer_provider, _ = TestBase.create_tracer_provider() self.tracer = self.tracer_provider.get_tracer(__name__)
self.tracer = tracer_provider.get_tracer(__name__)
def iterate_response(self, response): def iterate_response(self, response):
while True: while True:

View File

@ -26,9 +26,6 @@ from opentelemetry.test.test_base import TestBase
class TestDependencyConflicts(TestBase): class TestDependencyConflicts(TestBase):
def setUp(self):
pass
def test_get_dependency_conflicts_empty(self): def test_get_dependency_conflicts_empty(self):
self.assertIsNone(get_dependency_conflicts([])) self.assertIsNone(get_dependency_conflicts([]))

View File

@ -14,6 +14,8 @@
# pylint: disable=protected-access # pylint: disable=protected-access
import unittest
from opentelemetry import trace from opentelemetry import trace
from opentelemetry.instrumentation import propagators from opentelemetry.instrumentation import propagators
from opentelemetry.instrumentation.propagators import ( from opentelemetry.instrumentation.propagators import (
@ -39,7 +41,7 @@ class TestGlobals(TestBase):
propagators._RESPONSE_PROPAGATOR = original propagators._RESPONSE_PROPAGATOR = original
class TestDictHeaderSetter(TestBase): class TestDictHeaderSetter(unittest.TestCase):
def test_simple(self): def test_simple(self):
setter = DictHeaderSetter() setter = DictHeaderSetter()
carrier = {} carrier = {}

View File

@ -12,17 +12,17 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import unittest
from http import HTTPStatus from http import HTTPStatus
from opentelemetry.instrumentation.utils import ( from opentelemetry.instrumentation.utils import (
_python_path_without_directory, _python_path_without_directory,
http_status_to_status_code, http_status_to_status_code,
) )
from opentelemetry.test.test_base import TestBase
from opentelemetry.trace import StatusCode 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 # 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): def test_http_status_to_status_code(self):
for status_code, expected in ( for status_code, expected in (

View File

@ -21,14 +21,11 @@ def async_call(coro):
class TestFunctionalAsyncPG(TestBase): class TestFunctionalAsyncPG(TestBase):
@classmethod def setUp(self):
def setUpClass(cls): super().setUp()
super().setUpClass() self._tracer = self.tracer_provider.get_tracer(__name__)
cls._connection = None AsyncPGInstrumentor().instrument(tracer_provider=self.tracer_provider)
cls._cursor = None self._connection = async_call(
cls._tracer = cls.tracer_provider.get_tracer(__name__)
AsyncPGInstrumentor().instrument(tracer_provider=cls.tracer_provider)
cls._connection = async_call(
asyncpg.connect( asyncpg.connect(
database=POSTGRES_DB_NAME, database=POSTGRES_DB_NAME,
user=POSTGRES_USER, user=POSTGRES_USER,
@ -38,9 +35,9 @@ class TestFunctionalAsyncPG(TestBase):
) )
) )
@classmethod def tearDown(self):
def tearDownClass(cls):
AsyncPGInstrumentor().uninstrument() AsyncPGInstrumentor().uninstrument()
super().tearDown()
def check_span(self, span): def check_span(self, span):
self.assertEqual( self.assertEqual(
@ -148,16 +145,13 @@ class TestFunctionalAsyncPG(TestBase):
class TestFunctionalAsyncPG_CaptureParameters(TestBase): class TestFunctionalAsyncPG_CaptureParameters(TestBase):
@classmethod def setUp(self):
def setUpClass(cls): super().setUp()
super().setUpClass() self._tracer = self.tracer_provider.get_tracer(__name__)
cls._connection = None
cls._cursor = None
cls._tracer = cls.tracer_provider.get_tracer(__name__)
AsyncPGInstrumentor(capture_parameters=True).instrument( 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( asyncpg.connect(
database=POSTGRES_DB_NAME, database=POSTGRES_DB_NAME,
user=POSTGRES_USER, user=POSTGRES_USER,
@ -167,9 +161,9 @@ class TestFunctionalAsyncPG_CaptureParameters(TestBase):
) )
) )
@classmethod def tearDown(self):
def tearDownClass(cls):
AsyncPGInstrumentor().uninstrument() AsyncPGInstrumentor().uninstrument()
super().tearDown()
def check_span(self, span): def check_span(self, span):
self.assertEqual( self.assertEqual(

View File

@ -29,22 +29,10 @@ MYSQL_DB_NAME = os.getenv("MYSQL_DB_NAME", "opentelemetry-tests")
class TestFunctionalMysql(TestBase): 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): def setUp(self):
super().setUp() super().setUp()
self._tracer = self.tracer_provider.get_tracer(__name__)
MySQLInstrumentor().instrument()
self._connection = mysql.connector.connect( self._connection = mysql.connector.connect(
user=MYSQL_USER, user=MYSQL_USER,
password=MYSQL_PASSWORD, password=MYSQL_PASSWORD,
@ -54,6 +42,12 @@ class TestFunctionalMysql(TestBase):
) )
self._cursor = self._connection.cursor() self._cursor = self._connection.cursor()
def tearDown(self):
self._cursor.close()
self._connection.close()
MySQLInstrumentor().uninstrument()
super().tearDown()
def validate_spans(self, span_name): def validate_spans(self, span_name):
spans = self.memory_exporter.get_finished_spans() spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 2) self.assertEqual(len(spans), 2)

View File

@ -36,14 +36,11 @@ def async_call(coro):
class TestFunctionalAiopgConnect(TestBase): class TestFunctionalAiopgConnect(TestBase):
@classmethod def setUp(self):
def setUpClass(cls): super().setUp()
super().setUpClass() self._tracer = self.tracer_provider.get_tracer(__name__)
cls._connection = None AiopgInstrumentor().instrument(tracer_provider=self.tracer_provider)
cls._cursor = None self._connection = async_call(
cls._tracer = cls.tracer_provider.get_tracer(__name__)
AiopgInstrumentor().instrument(tracer_provider=cls.tracer_provider)
cls._connection = async_call(
aiopg.connect( aiopg.connect(
dbname=POSTGRES_DB_NAME, dbname=POSTGRES_DB_NAME,
user=POSTGRES_USER, user=POSTGRES_USER,
@ -52,15 +49,13 @@ class TestFunctionalAiopgConnect(TestBase):
port=POSTGRES_PORT, port=POSTGRES_PORT,
) )
) )
cls._cursor = async_call(cls._connection.cursor()) self._cursor = async_call(self._connection.cursor())
@classmethod def tearDown(self):
def tearDownClass(cls): self._cursor.close()
if cls._cursor: self._connection.close()
cls._cursor.close()
if cls._connection:
cls._connection.close()
AiopgInstrumentor().uninstrument() AiopgInstrumentor().uninstrument()
super().tearDown()
def validate_spans(self, span_name): def validate_spans(self, span_name):
spans = self.memory_exporter.get_finished_spans() spans = self.memory_exporter.get_finished_spans()
@ -121,18 +116,15 @@ class TestFunctionalAiopgConnect(TestBase):
class TestFunctionalAiopgCreatePool(TestBase): class TestFunctionalAiopgCreatePool(TestBase):
@classmethod def setUp(self):
def setUpClass(cls): super().setUp()
super().setUpClass() self._tracer = self.tracer_provider.get_tracer(__name__)
cls._connection = None AiopgInstrumentor().instrument(tracer_provider=self.tracer_provider)
cls._cursor = None self._dsn = (
cls._tracer = cls.tracer_provider.get_tracer(__name__)
AiopgInstrumentor().instrument(tracer_provider=cls.tracer_provider)
cls._dsn = (
f"dbname='{POSTGRES_DB_NAME}' user='{POSTGRES_USER}' password='{POSTGRES_PASSWORD}'" f"dbname='{POSTGRES_DB_NAME}' user='{POSTGRES_USER}' password='{POSTGRES_PASSWORD}'"
f" host='{POSTGRES_HOST}' port='{POSTGRES_PORT}'" f" host='{POSTGRES_HOST}' port='{POSTGRES_PORT}'"
) )
cls._pool = async_call( self._pool = async_call(
aiopg.create_pool( aiopg.create_pool(
dbname=POSTGRES_DB_NAME, dbname=POSTGRES_DB_NAME,
user=POSTGRES_USER, user=POSTGRES_USER,
@ -141,18 +133,15 @@ class TestFunctionalAiopgCreatePool(TestBase):
port=POSTGRES_PORT, port=POSTGRES_PORT,
) )
) )
cls._connection = async_call(cls._pool.acquire()) self._connection = async_call(self._pool.acquire())
cls._cursor = async_call(cls._connection.cursor()) self._cursor = async_call(self._connection.cursor())
@classmethod def tearDown(self):
def tearDownClass(cls): self._cursor.close()
if cls._cursor: self._connection.close()
cls._cursor.close() self._pool.close()
if cls._connection:
cls._connection.close()
if cls._pool:
cls._pool.close()
AiopgInstrumentor().uninstrument() AiopgInstrumentor().uninstrument()
super().tearDown()
def validate_spans(self, span_name): def validate_spans(self, span_name):
spans = self.memory_exporter.get_finished_spans() spans = self.memory_exporter.get_finished_spans()

View File

@ -30,30 +30,25 @@ POSTGRES_USER = os.getenv("POSTGRESQL_USER", "testuser")
class TestFunctionalPsycopg(TestBase): class TestFunctionalPsycopg(TestBase):
@classmethod def setUp(self):
def setUpClass(cls): super().setUp()
super().setUpClass() self._tracer = self.tracer_provider.get_tracer(__name__)
cls._connection = None Psycopg2Instrumentor().instrument(tracer_provider=self.tracer_provider)
cls._cursor = None self._connection = psycopg2.connect(
cls._tracer = cls.tracer_provider.get_tracer(__name__)
Psycopg2Instrumentor().instrument(tracer_provider=cls.tracer_provider)
cls._connection = psycopg2.connect(
dbname=POSTGRES_DB_NAME, dbname=POSTGRES_DB_NAME,
user=POSTGRES_USER, user=POSTGRES_USER,
password=POSTGRES_PASSWORD, password=POSTGRES_PASSWORD,
host=POSTGRES_HOST, host=POSTGRES_HOST,
port=POSTGRES_PORT, port=POSTGRES_PORT,
) )
cls._connection.set_session(autocommit=True) self._connection.set_session(autocommit=True)
cls._cursor = cls._connection.cursor() self._cursor = self._connection.cursor()
@classmethod def tearDown(self):
def tearDownClass(cls): self._cursor.close()
if cls._cursor: self._connection.close()
cls._cursor.close()
if cls._connection:
cls._connection.close()
Psycopg2Instrumentor().uninstrument() Psycopg2Instrumentor().uninstrument()
super().tearDown()
def validate_spans(self, span_name): def validate_spans(self, span_name):
spans = self.memory_exporter.get_finished_spans() spans = self.memory_exporter.get_finished_spans()

View File

@ -26,30 +26,25 @@ from opentelemetry.test.test_base import TestBase
class TestFunctionalPsycopg(TestBase): class TestFunctionalPsycopg(TestBase):
@classmethod def setUp(self):
def setUpClass(cls): super().setUp()
super().setUpClass() self._tracer = self.tracer_provider.get_tracer(__name__)
cls._connection = None
cls._cursor = None
cls._tracer = cls.tracer_provider.get_tracer(__name__)
Psycopg2Instrumentor().instrument(enable_commenter=True) Psycopg2Instrumentor().instrument(enable_commenter=True)
cls._connection = psycopg2.connect( self._connection = psycopg2.connect(
dbname=POSTGRES_DB_NAME, dbname=POSTGRES_DB_NAME,
user=POSTGRES_USER, user=POSTGRES_USER,
password=POSTGRES_PASSWORD, password=POSTGRES_PASSWORD,
host=POSTGRES_HOST, host=POSTGRES_HOST,
port=POSTGRES_PORT, port=POSTGRES_PORT,
) )
cls._connection.set_session(autocommit=True) self._connection.set_session(autocommit=True)
cls._cursor = cls._connection.cursor() self._cursor = self._connection.cursor()
@classmethod def tearDown(self):
def tearDownClass(cls): self._cursor.close()
if cls._cursor: self._connection.close()
cls._cursor.close()
if cls._connection:
cls._connection.close()
Psycopg2Instrumentor().uninstrument() Psycopg2Instrumentor().uninstrument()
super().tearDown()
def test_commenter_enabled(self): def test_commenter_enabled(self):
self._cursor.execute("SELECT 1;") self._cursor.execute("SELECT 1;")

View File

@ -28,16 +28,21 @@ MONGODB_COLLECTION_NAME = "test"
class TestFunctionalPymongo(TestBase): class TestFunctionalPymongo(TestBase):
@classmethod def setUp(self):
def setUpClass(cls): super().setUp()
super().setUpClass() self._tracer = self.tracer_provider.get_tracer(__name__)
cls._tracer = cls.tracer_provider.get_tracer(__name__) self.instrumentor = PymongoInstrumentor()
PymongoInstrumentor().instrument() self.instrumentor.instrument()
self.instrumentor._commandtracer_instance._tracer = self._tracer
client = MongoClient( client = MongoClient(
MONGODB_HOST, MONGODB_PORT, serverSelectionTimeoutMS=2000 MONGODB_HOST, MONGODB_PORT, serverSelectionTimeoutMS=2000
) )
db = client[MONGODB_DB_NAME] 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): def validate_spans(self):
spans = self.memory_exporter.get_finished_spans() spans = self.memory_exporter.get_finished_spans()

View File

@ -29,27 +29,24 @@ MYSQL_DB_NAME = os.getenv("MYSQL_DB_NAME", "opentelemetry-tests")
class TestFunctionalPyMysql(TestBase): class TestFunctionalPyMysql(TestBase):
@classmethod def setUp(self):
def setUpClass(cls): super().setUp()
super().setUpClass() self._tracer = self.tracer_provider.get_tracer(__name__)
cls._connection = None
cls._cursor = None
cls._tracer = cls.tracer_provider.get_tracer(__name__)
PyMySQLInstrumentor().instrument() PyMySQLInstrumentor().instrument()
cls._connection = pymy.connect( self._connection = pymy.connect(
user=MYSQL_USER, user=MYSQL_USER,
password=MYSQL_PASSWORD, password=MYSQL_PASSWORD,
host=MYSQL_HOST, host=MYSQL_HOST,
port=MYSQL_PORT, port=MYSQL_PORT,
database=MYSQL_DB_NAME, database=MYSQL_DB_NAME,
) )
cls._cursor = cls._connection.cursor() self._cursor = self._connection.cursor()
@classmethod def tearDown(self):
def tearDownClass(cls): self._cursor.close()
if cls._connection: self._connection.close()
cls._connection.close()
PyMySQLInstrumentor().uninstrument() PyMySQLInstrumentor().uninstrument()
super().tearDown()
def validate_spans(self, span_name): def validate_spans(self, span_name):
spans = self.memory_exporter.get_finished_spans() spans = self.memory_exporter.get_finished_spans()

View File

@ -31,8 +31,8 @@ class TestRedisInstrument(TestBase):
RedisInstrumentor().instrument(tracer_provider=self.tracer_provider) RedisInstrumentor().instrument(tracer_provider=self.tracer_provider)
def tearDown(self): def tearDown(self):
super().tearDown()
RedisInstrumentor().uninstrument() RedisInstrumentor().uninstrument()
super().tearDown()
def _check_span(self, span, name): def _check_span(self, span, name):
self.assertEqual(span.name, name) self.assertEqual(span.name, name)
@ -203,8 +203,8 @@ class TestAsyncRedisInstrument(TestBase):
RedisInstrumentor().instrument(tracer_provider=self.tracer_provider) RedisInstrumentor().instrument(tracer_provider=self.tracer_provider)
def tearDown(self): def tearDown(self):
super().tearDown()
RedisInstrumentor().uninstrument() RedisInstrumentor().uninstrument()
super().tearDown()
def _check_span(self, span, name): def _check_span(self, span, name):
self.assertEqual(span.name, name) self.assertEqual(span.name, name)
@ -383,8 +383,8 @@ class TestRedisDBIndexInstrument(TestBase):
RedisInstrumentor().instrument(tracer_provider=self.tracer_provider) RedisInstrumentor().instrument(tracer_provider=self.tracer_provider)
def tearDown(self): def tearDown(self):
super().tearDown()
RedisInstrumentor().uninstrument() RedisInstrumentor().uninstrument()
super().tearDown()
def _check_span(self, span, name): def _check_span(self, span, name):
self.assertEqual(span.name, name) self.assertEqual(span.name, name)

View File

@ -35,6 +35,7 @@ class SQLAlchemyInstrumentTestCase(TestBase):
""" """
def setUp(self): def setUp(self):
super().setUp()
# create a traced engine with the given arguments # create a traced engine with the given arguments
SQLAlchemyInstrumentor().instrument() SQLAlchemyInstrumentor().instrument()
dsn = ( dsn = (
@ -45,23 +46,23 @@ class SQLAlchemyInstrumentTestCase(TestBase):
# prepare a connection # prepare a connection
self.conn = self.engine.connect() self.conn = self.engine.connect()
super().setUp()
def tearDown(self): def tearDown(self):
# clear the database and dispose the engine # clear the database and dispose the engine
self.conn.close() self.conn.close()
self.engine.dispose() self.engine.dispose()
SQLAlchemyInstrumentor().uninstrument() SQLAlchemyInstrumentor().uninstrument()
super().tearDown()
def test_engine_traced(self): def test_engine_traced(self):
# ensures that the engine is traced # ensures that the engine is traced
rows = self.conn.execute("SELECT").fetchall() rows = self.conn.execute("SELECT").fetchall()
self.assertEqual(len(rows), 1) self.assertEqual(len(rows), 1)
traces = self.memory_exporter.get_finished_spans() spans = self.memory_exporter.get_finished_spans()
# trace composition # trace composition
self.assertEqual(len(traces), 1) self.assertEqual(len(spans), 2)
span = traces[0] span = spans[1]
# check subset of span fields # check subset of span fields
self.assertEqual(span.name, "SELECT opentelemetry-tests") self.assertEqual(span.name, "SELECT opentelemetry-tests")
self.assertIs(span.status.status_code, trace.StatusCode.UNSET) self.assertIs(span.status.status_code, trace.StatusCode.UNSET)

View File

@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import unittest
from unittest.mock import patch from unittest.mock import patch
from opentelemetry.test.test_base import TestBase
from opentelemetry.util.http import ( from opentelemetry.util.http import (
OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST, OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST,
OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE, 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( @patch.dict(
"os.environ", "os.environ",
{ {

View File

@ -12,13 +12,13 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import unittest
from unittest.mock import patch from unittest.mock import patch
from opentelemetry.test.test_base import TestBase
from opentelemetry.util.http import get_excluded_urls from opentelemetry.util.http import get_excluded_urls
class TestGetExcludedUrls(TestBase): class TestGetExcludedUrls(unittest.TestCase):
@patch.dict( @patch.dict(
"os.environ", "os.environ",
{ {