Skip to content

Commit

Permalink
Stop multiple calls to AsyncPGInstrumentor.__init__ from clobbering i…
Browse files Browse the repository at this point in the history
…nstance tracer attribute
  • Loading branch information
marcuslimdw committed Jan 31, 2024
1 parent 1a1163e commit dfba842
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ def _hydrate_span_from_args(connection, query, parameters) -> dict:


class AsyncPGInstrumentor(BaseInstrumentor):

_tracer = None
_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

0 comments on commit dfba842

Please sign in to comment.