Skip to content

Commit dfba842

Browse files
committed
Stop multiple calls to AsyncPGInstrumentor.__init__ from clobbering instance tracer attribute
1 parent 1a1163e commit dfba842

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,13 @@ def _hydrate_span_from_args(connection, query, parameters) -> dict:
9696

9797

9898
class AsyncPGInstrumentor(BaseInstrumentor):
99+
100+
_tracer = None
101+
_leading_comment_remover = re.compile(r"/\*.*?\*/")
102+
99103
def __init__(self, capture_parameters=False):
100104
super().__init__()
101105
self.capture_parameters = capture_parameters
102-
self._tracer = None
103-
self._leading_comment_remover = re.compile(r"^/\*.*?\*/")
104106

105107
def instrumentation_dependencies(self) -> Collection[str]:
106108
return _instruments

instrumentation/opentelemetry-instrumentation-asyncpg/tests/test_asyncpg_wrapper.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
class TestAsyncPGInstrumentation(TestBase):
8-
def test_duplicated_instrumentation(self):
8+
def test_duplicated_instrumentation_can_be_uninstrumented(self):
99
AsyncPGInstrumentor().instrument()
1010
AsyncPGInstrumentor().instrument()
1111
AsyncPGInstrumentor().instrument()
@@ -16,6 +16,12 @@ def test_duplicated_instrumentation(self):
1616
hasattr(method, "_opentelemetry_ext_asyncpg_applied")
1717
)
1818

19+
def test_duplicated_instrumentation_works(self):
20+
first = AsyncPGInstrumentor()
21+
first.instrument()
22+
second = AsyncPGInstrumentor()
23+
self.assertIsNotNone(first._tracer)
24+
1925
def test_duplicated_uninstrumentation(self):
2026
AsyncPGInstrumentor().instrument()
2127
AsyncPGInstrumentor().uninstrument()

0 commit comments

Comments
 (0)