Skip to content

Commit 67b6a42

Browse files
committed
wip
1 parent 06710d0 commit 67b6a42

File tree

3 files changed

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

3 files changed

+14
-12
lines changed

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

+11-11
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,7 @@ 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 =
103+
self.current_thread_span = span
104104
self.cursor_mapping[cursor] = span
105105
with trace.use_span(span, end_on_exit=False):
106106
if span.is_recording():
@@ -119,8 +119,8 @@ def _after_cur_exec(self, conn, cursor, statement, *args):
119119
self._cleanup(cursor)
120120

121121
def _handle_error(self, context):
122-
span = self.cursor_mapping[context.cursor]
123-
# span = self.current_thread_span
122+
# span = self.cursor_mapping[context.cursor]
123+
span = self.current_thread_span
124124
if span is None:
125125
return
126126

tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/mixins.py

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import contextlib
1616
import logging
1717
import threading
18+
import unittest
1819

1920
from sqlalchemy import Column, Integer, String, create_engine, insert
2021
from sqlalchemy.ext.declarative import declarative_base
@@ -242,4 +243,5 @@ def insert_players(session):
242243
close_all_sessions()
243244

244245
spans = self.memory_exporter.get_finished_spans()
246+
breakpoint()
245247
self.assertEqual(len(spans), 5)

tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_sqlite.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class SQLiteTestCase(SQLAlchemyTestMixin):
3535
def test_engine_execute_errors(self):
3636
# ensures that SQL errors are reported
3737
stmt = "SELECT * FROM a_wrong_table"
38-
with pytest.raises(OperationalError):
38+
with pytest.raises(Exception):
3939
with self.connection() as conn:
4040
conn.execute(stmt).fetchall()
4141

0 commit comments

Comments
 (0)