mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-08-01 09:13:23 +08:00
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:
@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
([#2151](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2151))
|
([#2151](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2151))
|
||||||
- `opentelemetry-resource-detector-azure` Added 10s timeout to VM Resource Detector
|
- `opentelemetry-resource-detector-azure` Added 10s timeout to VM Resource Detector
|
||||||
([#2119](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2119))
|
([#2119](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2119))
|
||||||
|
- `opentelemetry-instrumentation-asyncpg` Allow AsyncPGInstrumentor to be instantiated multiple times
|
||||||
|
([#1791](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1791))
|
||||||
- `opentelemetry-instrumentation-confluent-kafka` Add support for higher versions until 2.3.0 of confluent_kafka
|
- `opentelemetry-instrumentation-confluent-kafka` Add support for higher versions until 2.3.0 of confluent_kafka
|
||||||
([#2132](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2132))
|
([#2132](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2132))
|
||||||
- `opentelemetry-resource-detector-azure` Changed timeout to 4 seconds due to [timeout bug](https://github.com/open-telemetry/opentelemetry-python/issues/3644)
|
- `opentelemetry-resource-detector-azure` Changed timeout to 4 seconds due to [timeout bug](https://github.com/open-telemetry/opentelemetry-python/issues/3644)
|
||||||
|
@ -96,11 +96,13 @@ def _hydrate_span_from_args(connection, query, parameters) -> dict:
|
|||||||
|
|
||||||
|
|
||||||
class AsyncPGInstrumentor(BaseInstrumentor):
|
class AsyncPGInstrumentor(BaseInstrumentor):
|
||||||
|
|
||||||
|
_leading_comment_remover = re.compile(r"^/\*.*?\*/")
|
||||||
|
_tracer = None
|
||||||
|
|
||||||
def __init__(self, capture_parameters=False):
|
def __init__(self, capture_parameters=False):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.capture_parameters = capture_parameters
|
self.capture_parameters = capture_parameters
|
||||||
self._tracer = None
|
|
||||||
self._leading_comment_remover = re.compile(r"^/\*.*?\*/")
|
|
||||||
|
|
||||||
def instrumentation_dependencies(self) -> Collection[str]:
|
def instrumentation_dependencies(self) -> Collection[str]:
|
||||||
return _instruments
|
return _instruments
|
||||||
|
@ -5,7 +5,7 @@ from opentelemetry.test.test_base import TestBase
|
|||||||
|
|
||||||
|
|
||||||
class TestAsyncPGInstrumentation(TestBase):
|
class TestAsyncPGInstrumentation(TestBase):
|
||||||
def test_duplicated_instrumentation(self):
|
def test_duplicated_instrumentation_can_be_uninstrumented(self):
|
||||||
AsyncPGInstrumentor().instrument()
|
AsyncPGInstrumentor().instrument()
|
||||||
AsyncPGInstrumentor().instrument()
|
AsyncPGInstrumentor().instrument()
|
||||||
AsyncPGInstrumentor().instrument()
|
AsyncPGInstrumentor().instrument()
|
||||||
@ -16,6 +16,14 @@ class TestAsyncPGInstrumentation(TestBase):
|
|||||||
hasattr(method, "_opentelemetry_ext_asyncpg_applied")
|
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):
|
def test_duplicated_uninstrumentation(self):
|
||||||
AsyncPGInstrumentor().instrument()
|
AsyncPGInstrumentor().instrument()
|
||||||
AsyncPGInstrumentor().uninstrument()
|
AsyncPGInstrumentor().uninstrument()
|
||||||
|
Reference in New Issue
Block a user