Files
Marcus Lim 47caeab7af Stop multiple calls to AsyncPGInstrumentor.__init__ from clobbering instance attributes (#1791)
* Stop multiple calls to AsyncPGInstrumentor.__init__ from clobbering instance tracer attribute

* Remove class-level initialisation of _tracer

* Fix regex

* Add to changelog

* Fix lint errors

* Update CHANGELOG.md

Co-authored-by: Shalev Roda <65566801+shalevr@users.noreply.github.com>

* Set tracer in class definition to avoid lint error

---------

Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
Co-authored-by: Shalev Roda <65566801+shalevr@users.noreply.github.com>
2024-02-05 13:55:24 +02:00

37 lines
1.4 KiB
Python

from asyncpg import Connection
from opentelemetry.instrumentation.asyncpg import AsyncPGInstrumentor
from opentelemetry.test.test_base import TestBase
class TestAsyncPGInstrumentation(TestBase):
def test_duplicated_instrumentation_can_be_uninstrumented(self):
AsyncPGInstrumentor().instrument()
AsyncPGInstrumentor().instrument()
AsyncPGInstrumentor().instrument()
AsyncPGInstrumentor().uninstrument()
for method_name in ["execute", "fetch"]:
method = getattr(Connection, method_name, None)
self.assertFalse(
hasattr(method, "_opentelemetry_ext_asyncpg_applied")
)
def test_duplicated_instrumentation_works(self):
first = AsyncPGInstrumentor()
first.instrument()
second = AsyncPGInstrumentor()
second.instrument()
self.assertIsNotNone(first._tracer)
self.assertIsNotNone(second._tracer)
def test_duplicated_uninstrumentation(self):
AsyncPGInstrumentor().instrument()
AsyncPGInstrumentor().uninstrument()
AsyncPGInstrumentor().uninstrument()
AsyncPGInstrumentor().uninstrument()
for method_name in ["execute", "fetch"]:
method = getattr(Connection, method_name, None)
self.assertFalse(
hasattr(method, "_opentelemetry_ext_asyncpg_applied")
)