Skip to content

Commit 06710d0

Browse files
committed
test removing thread specific logic. upgrade to sqlalchemy ~1.4
1 parent c100b21 commit 06710d0

File tree

2 files changed

+14
-12
lines changed
  • instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy

2 files changed

+14
-12
lines changed

instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from threading import local
15+
# from threading import local
1616

1717
from sqlalchemy.event import listen # pylint: disable=no-name-in-module
1818

@@ -60,19 +60,19 @@ def __init__(self, tracer, engine):
6060
self.engine = engine
6161
self.vendor = _normalize_vendor(engine.name)
6262
self.cursor_mapping = {}
63-
self.local = local()
63+
# self.local = local()
6464

6565
listen(engine, "before_cursor_execute", self._before_cur_exec)
6666
listen(engine, "after_cursor_execute", self._after_cur_exec)
6767
listen(engine, "handle_error", self._handle_error)
6868

69-
@property
70-
def current_thread_span(self):
71-
return getattr(self.local, "current_span", None)
69+
# @property
70+
# def current_thread_span(self):
71+
# return getattr(self.local, "current_span", None)
7272

73-
@current_thread_span.setter
74-
def current_thread_span(self, span):
75-
setattr(self.local, "current_span", span)
73+
# @current_thread_span.setter
74+
# def current_thread_span(self, span):
75+
# setattr(self.local, "current_span", span)
7676

7777
def _operation_name(self, db_name, statement):
7878
parts = []
@@ -100,7 +100,8 @@ def _before_cur_exec(self, conn, cursor, statement, *args):
100100
self._operation_name(db_name, statement),
101101
kind=trace.SpanKind.CLIENT,
102102
)
103-
self.current_thread_span = self.cursor_mapping[cursor] = span
103+
# self.current_thread_span =
104+
self.cursor_mapping[cursor] = span
104105
with trace.use_span(span, end_on_exit=False):
105106
if span.is_recording():
106107
span.set_attribute(SpanAttributes.DB_STATEMENT, statement)
@@ -118,7 +119,8 @@ def _after_cur_exec(self, conn, cursor, statement, *args):
118119
self._cleanup(cursor)
119120

120121
def _handle_error(self, context):
121-
span = self.current_thread_span
122+
span = self.cursor_mapping[context.cursor]
123+
# span = self.current_thread_span
122124
if span is None:
123125
return
124126

tox.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ commands =
335335

336336
[testenv:lint]
337337
basepython: python3.9
338-
recreate = False
338+
recreate = False
339339
deps =
340340
-c dev-requirements.txt
341341
flaky
@@ -405,7 +405,7 @@ deps =
405405
PyMySQL ~= 0.10.1
406406
psycopg2 ~= 2.8.4
407407
aiopg >= 0.13.0, < 1.3.0
408-
sqlalchemy ~= 1.3.16
408+
sqlalchemy ~= 1.4
409409
redis ~= 3.3.11
410410
celery[pytest] >= 4.0, < 6.0
411411
protobuf>=3.13.0

0 commit comments

Comments
 (0)