Skip to content

Commit

Permalink
test removing thread specific logic. upgrade to sqlalchemy ~1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
mnbbrown committed Jul 6, 2021
1 parent c100b21 commit 06710d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ commands =

[testenv:lint]
basepython: python3.9
recreate = False
recreate = False
deps =
-c dev-requirements.txt
flaky
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 06710d0

Please sign in to comment.