mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-08-02 19:47:17 +08:00
Add support to instrument multiple sqlalchemy engines (#1132)
* Override __new__ to instrument multiple engines * add possibility to instrument mutiple engines * update changelog * update return type in doc * fix CHANGELOG * format * fix test * Check if engines isinstance Sequence Co-authored-by: Diego Hurtado <ocelotl@users.noreply.github.com>
This commit is contained in:
@ -50,6 +50,24 @@ class TestSqlalchemyInstrumentation(TestBase):
|
||||
self.assertEqual(spans[0].name, "SELECT :memory:")
|
||||
self.assertEqual(spans[0].kind, trace.SpanKind.CLIENT)
|
||||
|
||||
def test_instrument_two_engines(self):
|
||||
engine_1 = create_engine("sqlite:///:memory:")
|
||||
engine_2 = create_engine("sqlite:///:memory:")
|
||||
|
||||
SQLAlchemyInstrumentor().instrument(
|
||||
engines=[engine_1, engine_2],
|
||||
tracer_provider=self.tracer_provider,
|
||||
)
|
||||
|
||||
cnx_1 = engine_1.connect()
|
||||
cnx_1.execute("SELECT 1 + 1;").fetchall()
|
||||
cnx_2 = engine_2.connect()
|
||||
cnx_2.execute("SELECT 1 + 1;").fetchall()
|
||||
|
||||
spans = self.memory_exporter.get_finished_spans()
|
||||
|
||||
self.assertEqual(len(spans), 2)
|
||||
|
||||
@pytest.mark.skipif(
|
||||
not sqlalchemy.__version__.startswith("1.4"),
|
||||
reason="only run async tests for 1.4",
|
||||
|
Reference in New Issue
Block a user