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>
This commit is contained in:
Marcus Lim
2024-02-05 19:55:24 +08:00
committed by GitHub
parent 13ce910f14
commit 47caeab7af
3 changed files with 15 additions and 3 deletions

View File

@ -5,7 +5,7 @@ from opentelemetry.test.test_base import TestBase
class TestAsyncPGInstrumentation(TestBase):
def test_duplicated_instrumentation(self):
def test_duplicated_instrumentation_can_be_uninstrumented(self):
AsyncPGInstrumentor().instrument()
AsyncPGInstrumentor().instrument()
AsyncPGInstrumentor().instrument()
@ -16,6 +16,14 @@ class TestAsyncPGInstrumentation(TestBase):
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()