diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py index e69c6dbcb4..6adf48cd26 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py +++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from threading import local +# from threading import local from sqlalchemy.event import listen # pylint: disable=no-name-in-module @@ -60,19 +60,19 @@ def __init__(self, tracer, engine): self.engine = engine self.vendor = _normalize_vendor(engine.name) self.cursor_mapping = {} - self.local = local() + # self.local = local() listen(engine, "before_cursor_execute", self._before_cur_exec) listen(engine, "after_cursor_execute", self._after_cur_exec) listen(engine, "handle_error", self._handle_error) - @property - def current_thread_span(self): - return getattr(self.local, "current_span", None) + # @property + # def current_thread_span(self): + # return getattr(self.local, "current_span", None) - @current_thread_span.setter - def current_thread_span(self, span): - setattr(self.local, "current_span", span) + # @current_thread_span.setter + # def current_thread_span(self, span): + # setattr(self.local, "current_span", span) def _operation_name(self, db_name, statement): parts = [] @@ -100,7 +100,8 @@ def _before_cur_exec(self, conn, cursor, statement, *args): self._operation_name(db_name, statement), kind=trace.SpanKind.CLIENT, ) - self.current_thread_span = self.cursor_mapping[cursor] = span + # self.current_thread_span = + self.cursor_mapping[cursor] = span with trace.use_span(span, end_on_exit=False): if span.is_recording(): span.set_attribute(SpanAttributes.DB_STATEMENT, statement) @@ -118,7 +119,8 @@ def _after_cur_exec(self, conn, cursor, statement, *args): self._cleanup(cursor) def _handle_error(self, context): - span = self.current_thread_span + span = self.cursor_mapping[context.cursor] + # span = self.current_thread_span if span is None: return diff --git a/tox.ini b/tox.ini index 08e2f54c0e..23dbae58e9 100644 --- a/tox.ini +++ b/tox.ini @@ -335,7 +335,7 @@ commands = [testenv:lint] basepython: python3.9 -recreate = False +recreate = False deps = -c dev-requirements.txt flaky @@ -405,7 +405,7 @@ deps = PyMySQL ~= 0.10.1 psycopg2 ~= 2.8.4 aiopg >= 0.13.0, < 1.3.0 - sqlalchemy ~= 1.3.16 + sqlalchemy ~= 1.4 redis ~= 3.3.11 celery[pytest] >= 4.0, < 6.0 protobuf>=3.13.0