Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop multiple calls to AsyncPGInstrumentor.__init__ from clobbering instance attributes #1791

Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ def _hydrate_span_from_args(connection, query, parameters) -> dict:


class AsyncPGInstrumentor(BaseInstrumentor):

_leading_comment_remover = re.compile(r"^/\*.*?\*/")

def __init__(self, capture_parameters=False):
super().__init__()
self.capture_parameters = capture_parameters
self._tracer = None
self._leading_comment_remover = re.compile(r"^/\*.*?\*/")

def instrumentation_dependencies(self) -> Collection[str]:
return _instruments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class TestAsyncPGInstrumentation(TestBase):
def test_duplicated_instrumentation(self):
def test_duplicated_instrumentation_can_be_uninstrumented(self):
AsyncPGInstrumentor().instrument()
AsyncPGInstrumentor().instrument()
AsyncPGInstrumentor().instrument()
Expand All @@ -16,6 +16,12 @@ def test_duplicated_instrumentation(self):
hasattr(method, "_opentelemetry_ext_asyncpg_applied")
)

def test_duplicated_instrumentation_works(self):
first = AsyncPGInstrumentor()
first.instrument()
second = AsyncPGInstrumentor()
self.assertIsNotNone(first._tracer)

def test_duplicated_uninstrumentation(self):
AsyncPGInstrumentor().instrument()
AsyncPGInstrumentor().uninstrument()
Expand Down
Loading