|
41 | 41 | import logging |
42 | 42 | import re |
43 | 43 | import typing |
44 | | -from abc import ABC, abstractmethod |
45 | 44 |
|
46 | 45 | import wrapt |
47 | 46 |
|
48 | 47 | from opentelemetry import trace as trace_api |
| 48 | +from opentelemetry.instrumentation.dbapi.proxy import ( |
| 49 | + BaseTracedConnectionProxy, |
| 50 | + BaseTracedCursorProxy, |
| 51 | +) |
49 | 52 | from opentelemetry.instrumentation.dbapi.version import __version__ |
50 | 53 | from opentelemetry.instrumentation.sqlcommenter_utils import _add_sql_comment |
51 | 54 | from opentelemetry.instrumentation.utils import ( |
@@ -391,31 +394,6 @@ def get_connection_attributes(self, connection): |
391 | 394 | self.span_attributes[SpanAttributes.NET_PEER_PORT] = port |
392 | 395 |
|
393 | 396 |
|
394 | | -class BaseTracedConnectionProxy(ABC, wrapt.ObjectProxy): |
395 | | - # pylint: disable=unused-argument |
396 | | - def __init__(self, connection, *args, **kwargs): |
397 | | - wrapt.ObjectProxy.__init__(self, connection) |
398 | | - |
399 | | - def __getattribute__(self, name): |
400 | | - if object.__getattribute__(self, name): |
401 | | - return object.__getattribute__(self, name) |
402 | | - |
403 | | - return object.__getattribute__( |
404 | | - object.__getattribute__(self, "_connection"), name |
405 | | - ) |
406 | | - |
407 | | - @abstractmethod |
408 | | - def cursor(self, *args, **kwargs): |
409 | | - """Returns instrumented database query cursor""" |
410 | | - |
411 | | - def __enter__(self): |
412 | | - self.__wrapped__.__enter__() |
413 | | - return self |
414 | | - |
415 | | - def __exit__(self, *args, **kwargs): |
416 | | - self.__wrapped__.__exit__(*args, **kwargs) |
417 | | - |
418 | | - |
419 | 397 | def get_traced_connection_proxy( |
420 | 398 | connection, db_api_integration, *args, **kwargs |
421 | 399 | ): |
@@ -550,38 +528,6 @@ def traced_execution( |
550 | 528 | return query_method(*args, **kwargs) |
551 | 529 |
|
552 | 530 |
|
553 | | -# pylint: disable=abstract-method |
554 | | -class BaseTracedCursorProxy(ABC, wrapt.ObjectProxy): |
555 | | - # pylint: disable=unused-argument |
556 | | - @abstractmethod |
557 | | - def __init__(self, cursor, *args, **kwargs): |
558 | | - """Wrap db client cursor for tracing""" |
559 | | - wrapt.ObjectProxy.__init__(self, cursor) |
560 | | - self._cursor_tracer = None |
561 | | - |
562 | | - def callproc(self, *args, **kwargs): |
563 | | - return self._cursor_tracer.traced_execution( |
564 | | - self.__wrapped__, self.__wrapped__.callproc, *args, **kwargs |
565 | | - ) |
566 | | - |
567 | | - def execute(self, *args, **kwargs): |
568 | | - return self._cursor_tracer.traced_execution( |
569 | | - self.__wrapped__, self.__wrapped__.execute, *args, **kwargs |
570 | | - ) |
571 | | - |
572 | | - def executemany(self, *args, **kwargs): |
573 | | - return self._cursor_tracer.traced_execution( |
574 | | - self.__wrapped__, self.__wrapped__.executemany, *args, **kwargs |
575 | | - ) |
576 | | - |
577 | | - def __enter__(self): |
578 | | - self.__wrapped__.__enter__() |
579 | | - return self |
580 | | - |
581 | | - def __exit__(self, *args, **kwargs): |
582 | | - self.__wrapped__.__exit__(*args, **kwargs) |
583 | | - |
584 | | - |
585 | 531 | def get_traced_cursor_proxy(cursor, db_api_integration, *args, **kwargs): |
586 | 532 | class TracedCursorProxy(BaseTracedCursorProxy): |
587 | 533 | def __init__(self, *args, **kwargs): |
|
0 commit comments