Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ad2493d

Browse files
committedDec 22, 2020
Updated dbapi and psycopg2 instrumentations.
Changes: - Update dbapi instrumentation to use the SQL statement name as the span instead of the entire SQL query. - Renamed TracedCursor with CursorTracing. The class was not a valid Cursor so the name was confusing. - Updated CursorTracing's (previously TracedCursor) traced_execution method to accept the cursor instance as the first argument. This is required as for some dbapi implementations, we need a reference to the cursor in order to correctly format the SQL query. - Updated psycopg2 instrumentation to leverage dbapi's `cursor_factory` mechanism instead of wrapping the cursor with wrapt. This results in a simpler instrumentation without monkey patching objects at runtime and allows psycopg2's type registration system to work. This should make it possible to use psycopg2 instrumentation when using the JSONB feature or with frameworks like Django.
1 parent 7a1be91 commit ad2493d

File tree

13 files changed

+268
-88
lines changed

13 files changed

+268
-88
lines changed
 

‎.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ lib64
2222
__pycache__
2323
venv*/
2424
.venv*/
25-
opentelemetry-python-core*/
25+
/opentelemetry-python-core*/
2626
/opentelemetry-python-core
2727

2828
# Installer logs

‎CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4141
([#253](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/253))
4242
- `opentelemetry-instrumentation-requests`, `opentelemetry-instrumentation-urllib` Fix span name callback parameters
4343
- ([#259](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/259))
44+
- `opentelemetry-instrumentation-dbapi`, `TracedCursor` replaced by `CursorTracer`
45+
([#246](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/246))
46+
- `opentelemetry-instrumentation-psycopg2`, Added support for psycopg2 registered types.
47+
([#246](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/246))
48+
- `opentelemetry-instrumentation-dbapi`, `opentelemetry-instrumentation-psycopg2`, `opentelemetry-instrumentation-mysql`, `opentelemetry-instrumentation-pymysql`, `opentelemetry-instrumentation-aiopg` Use SQL command name as the span operation name instead of the entire query.
49+
([#246](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/246))
4450

4551
## [0.16b1](https://github.com/open-telemetry/opentelemetry-python-contrib/releases/tag/v0.16b1) - 2020-11-26
4652

‎instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/aiopg_integration.py

+17-13
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from aiopg.utils import _ContextManager, _PoolAcquireContextManager
55

66
from opentelemetry.instrumentation.dbapi import (
7+
CursorTracer,
78
DatabaseApiIntegration,
8-
TracedCursor,
99
)
1010
from opentelemetry.trace import SpanKind
1111
from opentelemetry.trace.status import Status, StatusCode
@@ -94,25 +94,29 @@ async def _acquire(self):
9494
return TracedPoolProxy(pool, *args, **kwargs)
9595

9696

97-
class AsyncTracedCursor(TracedCursor):
97+
class AsyncCursorTracer(CursorTracer):
9898
async def traced_execution(
9999
self,
100+
cursor,
100101
query_method: typing.Callable[..., typing.Any],
101102
*args: typing.Tuple[typing.Any, typing.Any],
102103
**kwargs: typing.Dict[typing.Any, typing.Any]
103104
):
104105
name = ""
105-
if len(args) > 0 and args[0]:
106-
name = args[0]
107-
elif self._db_api_integration.database:
108-
name = self._db_api_integration.database
109-
else:
110-
name = self._db_api_integration.name
106+
if args:
107+
name = self.get_operation_name(cursor, args)
108+
109+
if not name:
110+
name = (
111+
self._db_api_integration.database
112+
if self._db_api_integration.database
113+
else self._db_api_integration.name
114+
)
111115

112116
with self._db_api_integration.get_tracer().start_as_current_span(
113117
name, kind=SpanKind.CLIENT
114118
) as span:
115-
self._populate_span(span, *args)
119+
self._populate_span(cursor, span, *args)
116120
try:
117121
result = await query_method(*args, **kwargs)
118122
return result
@@ -123,7 +127,7 @@ async def traced_execution(
123127

124128

125129
def get_traced_cursor_proxy(cursor, db_api_integration, *args, **kwargs):
126-
_traced_cursor = AsyncTracedCursor(db_api_integration)
130+
_traced_cursor = AsyncCursorTracer(db_api_integration)
127131

128132
# pylint: disable=abstract-method
129133
class AsyncTracedCursorProxy(AsyncProxyObject):
@@ -134,19 +138,19 @@ def __init__(self, cursor, *args, **kwargs):
134138

135139
async def execute(self, *args, **kwargs):
136140
result = await _traced_cursor.traced_execution(
137-
self.__wrapped__.execute, *args, **kwargs
141+
self, self.__wrapped__.execute, *args, **kwargs
138142
)
139143
return result
140144

141145
async def executemany(self, *args, **kwargs):
142146
result = await _traced_cursor.traced_execution(
143-
self.__wrapped__.executemany, *args, **kwargs
147+
self, self.__wrapped__.executemany, *args, **kwargs
144148
)
145149
return result
146150

147151
async def callproc(self, *args, **kwargs):
148152
result = await _traced_cursor.traced_execution(
149-
self.__wrapped__.callproc, *args, **kwargs
153+
self, self.__wrapped__.callproc, *args, **kwargs
150154
)
151155
return result
152156

‎instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def test_span_succeeded(self):
215215
spans_list = self.memory_exporter.get_finished_spans()
216216
self.assertEqual(len(spans_list), 1)
217217
span = spans_list[0]
218-
self.assertEqual(span.name, "Test query")
218+
self.assertEqual(span.name, "Test")
219219
self.assertIs(span.kind, trace_api.SpanKind.CLIENT)
220220

221221
self.assertEqual(span.attributes["component"], "testcomponent")

‎instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py

+42-19
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def trace_integration(
6060
connection_attributes: typing.Dict = None,
6161
tracer_provider: typing.Optional[TracerProvider] = None,
6262
capture_parameters: bool = False,
63+
db_api_integration_factory=None,
6364
):
6465
"""Integrate with DB API library.
6566
https://www.python.org/dev/peps/pep-0249/
@@ -86,6 +87,7 @@ def trace_integration(
8687
version=__version__,
8788
tracer_provider=tracer_provider,
8889
capture_parameters=capture_parameters,
90+
db_api_integration_factory=db_api_integration_factory,
8991
)
9092

9193

@@ -99,6 +101,7 @@ def wrap_connect(
99101
version: str = "",
100102
tracer_provider: typing.Optional[TracerProvider] = None,
101103
capture_parameters: bool = False,
104+
db_api_integration_factory=None,
102105
):
103106
"""Integrate with DB API library.
104107
https://www.python.org/dev/peps/pep-0249/
@@ -115,6 +118,9 @@ def wrap_connect(
115118
capture_parameters: Configure if db.statement.parameters should be captured.
116119
117120
"""
121+
db_api_integration_factory = (
122+
db_api_integration_factory or DatabaseApiIntegration
123+
)
118124

119125
# pylint: disable=unused-argument
120126
def wrap_connect_(
@@ -123,7 +129,7 @@ def wrap_connect_(
123129
args: typing.Tuple[typing.Any, typing.Any],
124130
kwargs: typing.Dict[typing.Any, typing.Any],
125131
):
126-
db_integration = DatabaseApiIntegration(
132+
db_integration = db_api_integration_factory(
127133
name,
128134
database_component,
129135
database_type=database_type,
@@ -314,16 +320,19 @@ def __exit__(self, *args, **kwargs):
314320
return TracedConnectionProxy(connection, *args, **kwargs)
315321

316322

317-
class TracedCursor:
323+
class CursorTracer:
318324
def __init__(self, db_api_integration: DatabaseApiIntegration):
319325
self._db_api_integration = db_api_integration
320326

321327
def _populate_span(
322-
self, span: trace_api.Span, *args: typing.Tuple[typing.Any, typing.Any]
328+
self,
329+
span: trace_api.Span,
330+
cursor,
331+
*args: typing.Tuple[typing.Any, typing.Any]
323332
):
324333
if not span.is_recording():
325334
return
326-
statement = args[0] if args else ""
335+
statement = self.get_statement(cursor, args)
327336
span.set_attribute(
328337
"component", self._db_api_integration.database_component
329338
)
@@ -342,24 +351,38 @@ def _populate_span(
342351
if self._db_api_integration.capture_parameters and len(args) > 1:
343352
span.set_attribute("db.statement.parameters", str(args[1]))
344353

354+
def get_operation_name(self, cursor, args):
355+
if args and isinstance(args[0], str):
356+
return args[0].split(" ")[0]
357+
return ""
358+
359+
def get_statement(self, cursor, args):
360+
if not args:
361+
return ""
362+
statement = args[0]
363+
if isinstance(statement, bytes):
364+
return statement.decode("utf8", "replace")
365+
return statement
366+
345367
def traced_execution(
346368
self,
369+
cursor,
347370
query_method: typing.Callable[..., typing.Any],
348371
*args: typing.Tuple[typing.Any, typing.Any],
349372
**kwargs: typing.Dict[typing.Any, typing.Any]
350373
):
351-
name = ""
352-
if args:
353-
name = args[0]
354-
elif self._db_api_integration.database:
355-
name = self._db_api_integration.database
356-
else:
357-
name = self._db_api_integration.name
374+
name = self.get_operation_name(cursor, args)
375+
if not name:
376+
name = (
377+
self._db_api_integration.database
378+
if self._db_api_integration.database
379+
else self._db_api_integration.name
380+
)
358381

359382
with self._db_api_integration.get_tracer().start_as_current_span(
360383
name, kind=SpanKind.CLIENT
361384
) as span:
362-
self._populate_span(span, *args)
385+
self._populate_span(span, cursor, *args)
363386
try:
364387
result = query_method(*args, **kwargs)
365388
return result
@@ -370,7 +393,7 @@ def traced_execution(
370393

371394

372395
def get_traced_cursor_proxy(cursor, db_api_integration, *args, **kwargs):
373-
_traced_cursor = TracedCursor(db_api_integration)
396+
_cursor_tracer = CursorTracer(db_api_integration)
374397

375398
# pylint: disable=abstract-method
376399
class TracedCursorProxy(wrapt.ObjectProxy):
@@ -380,18 +403,18 @@ def __init__(self, cursor, *args, **kwargs):
380403
wrapt.ObjectProxy.__init__(self, cursor)
381404

382405
def execute(self, *args, **kwargs):
383-
return _traced_cursor.traced_execution(
384-
self.__wrapped__.execute, *args, **kwargs
406+
return _cursor_tracer.traced_execution(
407+
self.__wrapped__, self.__wrapped__.execute, *args, **kwargs
385408
)
386409

387410
def executemany(self, *args, **kwargs):
388-
return _traced_cursor.traced_execution(
389-
self.__wrapped__.executemany, *args, **kwargs
411+
return _cursor_tracer.traced_execution(
412+
self.__wrapped__, self.__wrapped__.executemany, *args, **kwargs
390413
)
391414

392415
def callproc(self, *args, **kwargs):
393-
return _traced_cursor.traced_execution(
394-
self.__wrapped__.callproc, *args, **kwargs
416+
return _cursor_tracer.traced_execution(
417+
self.__wrapped__, self.__wrapped__.callproc, *args, **kwargs
395418
)
396419

397420
def __enter__(self):

‎instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_span_succeeded(self):
5050
spans_list = self.memory_exporter.get_finished_spans()
5151
self.assertEqual(len(spans_list), 1)
5252
span = spans_list[0]
53-
self.assertEqual(span.name, "Test query")
53+
self.assertEqual(span.name, "Test")
5454
self.assertIs(span.kind, trace_api.SpanKind.CLIENT)
5555

5656
self.assertEqual(span.attributes["component"], "testcomponent")
@@ -93,7 +93,7 @@ def test_span_succeeded_with_capture_of_statement_parameters(self):
9393
spans_list = self.memory_exporter.get_finished_spans()
9494
self.assertEqual(len(spans_list), 1)
9595
span = spans_list[0]
96-
self.assertEqual(span.name, "Test query")
96+
self.assertEqual(span.name, "Test")
9797
self.assertIs(span.kind, trace_api.SpanKind.CLIENT)
9898

9999
self.assertEqual(span.attributes["component"], "testcomponent")

‎instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/__init__.py

+90-25
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,17 @@
3939
---
4040
"""
4141

42+
import typing
43+
4244
import psycopg2
45+
from psycopg2.extensions import cursor
46+
from psycopg2.sql import Composed
4347

4448
from opentelemetry.instrumentation import dbapi
4549
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
4650
from opentelemetry.instrumentation.psycopg2.version import __version__
47-
from opentelemetry.trace import get_tracer
51+
52+
OTEL_CURSOR_FACTORY_KEY = "_otel_orig_cursor_factory"
4853

4954

5055
class Psycopg2Instrumentor(BaseInstrumentor):
@@ -62,7 +67,6 @@ def _instrument(self, **kwargs):
6267
"""Integrate with PostgreSQL Psycopg library.
6368
Psycopg: http://initd.org/psycopg/
6469
"""
65-
6670
tracer_provider = kwargs.get("tracer_provider")
6771

6872
dbapi.wrap_connect(
@@ -74,39 +78,100 @@ def _instrument(self, **kwargs):
7478
self._CONNECTION_ATTRIBUTES,
7579
version=__version__,
7680
tracer_provider=tracer_provider,
81+
db_api_integration_factory=DatabaseApiIntegration,
7782
)
7883

7984
def _uninstrument(self, **kwargs):
8085
""""Disable Psycopg2 instrumentation"""
8186
dbapi.unwrap_connect(psycopg2, "connect")
8287

83-
# pylint:disable=no-self-use
88+
# TODO(owais): check if core dbapi can do this for all dbapi implementations e.g, pymysql and mysql
8489
def instrument_connection(self, connection):
85-
"""Enable instrumentation in a Psycopg2 connection.
90+
setattr(connection, OTEL_CURSOR_FACTORY_KEY, connection.cursor_factory)
91+
connection.cursor_factory = _new_cursor_factory()
92+
return connection
8693

87-
Args:
88-
connection: The connection to instrument.
94+
# TODO(owais): check if core dbapi can do this for all dbapi implementations e.g, pymysql and mysql
95+
def uninstrument_connection(self, connection):
96+
connection.cursor_factory = getattr(
97+
connection, OTEL_CURSOR_FACTORY_KEY, None
98+
)
99+
return connection
100+
101+
102+
# TODO(owais): check if core dbapi can do this for all dbapi implementations e.g, pymysql and mysql
103+
class DatabaseApiIntegration(dbapi.DatabaseApiIntegration):
104+
def wrapped_connection(
105+
self,
106+
connect_method: typing.Callable[..., typing.Any],
107+
args: typing.Tuple[typing.Any, typing.Any],
108+
kwargs: typing.Dict[typing.Any, typing.Any],
109+
):
110+
"""Add object proxy to connection object."""
111+
base_cursor_factory = kwargs.pop("cursor_factory", None)
112+
new_factory_kwargs = {"dbapi": self}
113+
if base_cursor_factory:
114+
new_factory_kwargs["base_factory"] = base_cursor_factory
115+
kwargs["cursor_factory"] = _new_cursor_factory(**new_factory_kwargs)
116+
connection = connect_method(*args, **kwargs)
117+
self.get_connection_attributes(connection)
118+
return connection
119+
120+
121+
class CursorTracer(dbapi.CursorTracer):
122+
def get_operation_name(self, cursor, args):
123+
if not args:
124+
return ""
125+
126+
statement = args[0]
127+
if isinstance(statement, Composed):
128+
print('-=---------- composed')
129+
print(statement)
130+
print('-=----------')
131+
statement = statement.as_string(cursor)
132+
133+
if isinstance(statement, str):
134+
return statement.split(" ")[0]
135+
136+
return ""
137+
138+
def get_statement(self, cursor, args):
139+
if not args:
140+
return ""
141+
142+
statement = args[0]
143+
if isinstance(statement, Composed):
144+
statement = statement.as_string(cursor)
145+
return statement
146+
147+
148+
def _new_cursor_factory(dbapi=None, base_factory=None):
149+
if not dbapi:
150+
dbapi = DatabaseApiIntegration(
151+
__name__,
152+
Psycopg2Instrumentor._DATABASE_COMPONENT,
153+
database_type=Psycopg2Instrumentor._DATABASE_TYPE,
154+
connection_attributes=Psycopg2Instrumentor._CONNECTION_ATTRIBUTES,
155+
version=__version__,
156+
)
89157

90-
Returns:
91-
An instrumented connection.
92-
"""
93-
tracer = get_tracer(__name__, __version__)
158+
base_factory = base_factory or cursor
159+
_cursor_tracer = CursorTracer(dbapi)
94160

95-
return dbapi.instrument_connection(
96-
tracer,
97-
connection,
98-
self._DATABASE_COMPONENT,
99-
self._DATABASE_TYPE,
100-
self._CONNECTION_ATTRIBUTES,
101-
)
161+
class TracedCursorFactory(base_factory):
162+
def execute(self, *args, **kwargs):
163+
return _cursor_tracer.traced_execution(
164+
self, super().execute, *args, **kwargs
165+
)
102166

103-
def uninstrument_connection(self, connection):
104-
"""Disable instrumentation in a Psycopg2 connection.
167+
def executemany(self, *args, **kwargs):
168+
return _cursor_tracer.traced_execution(
169+
self, super().executemany, *args, **kwargs
170+
)
105171

106-
Args:
107-
connection: The connection to uninstrument.
172+
def callproc(self, *args, **kwargs):
173+
return _cursor_tracer.traced_execution(
174+
self, super().callproc, *args, **kwargs
175+
)
108176

109-
Returns:
110-
An uninstrumented connection.
111-
"""
112-
return dbapi.uninstrument_connection(connection)
177+
return TracedCursorFactory

‎instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py

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

15+
import types
1516
from unittest import mock
1617

1718
import psycopg2
@@ -22,15 +23,69 @@
2223
from opentelemetry.test.test_base import TestBase
2324

2425

26+
class MockCursor:
27+
28+
execute = mock.MagicMock(spec=types.MethodType)
29+
execute.__name__ = "execute"
30+
31+
executemany = mock.MagicMock(spec=types.MethodType)
32+
executemany.__name__ = "executemany"
33+
34+
callproc = mock.MagicMock(spec=types.MethodType)
35+
callproc.__name__ = "callproc"
36+
37+
rowcount = "SomeRowCount"
38+
39+
def __init__(self, *args, **kwargs):
40+
pass
41+
42+
def __enter__(self):
43+
return self
44+
45+
def __exit__(self, *args):
46+
return self
47+
48+
49+
class MockConnection(object):
50+
51+
commit = mock.MagicMock(spec=types.MethodType)
52+
commit.__name__ = "commit"
53+
54+
rollback = mock.MagicMock(spec=types.MethodType)
55+
rollback.__name__ = "rollback"
56+
57+
def __init__(self, *args, **kwargs):
58+
self.cursor_factory = kwargs.pop("cursor_factory", None)
59+
60+
def cursor(self):
61+
if self.cursor_factory:
62+
return self.cursor_factory(self)
63+
return MockCursor()
64+
65+
def get_dsn_parameters(self):
66+
return dict(dbname="test")
67+
68+
2569
class TestPostgresqlIntegration(TestBase):
70+
def setUp(self):
71+
self.cursor_mock = mock.patch(
72+
"opentelemetry.instrumentation.psycopg2.cursor", MockCursor
73+
)
74+
self.connection_mock = mock.patch("psycopg2.connect", MockConnection)
75+
76+
self.cursor_mock.start()
77+
self.connection_mock.start()
78+
2679
def tearDown(self):
2780
super().tearDown()
81+
self.memory_exporter.clear()
82+
self.cursor_mock.stop()
83+
self.connection_mock.stop()
2884
with self.disable_logging():
2985
Psycopg2Instrumentor().uninstrument()
3086

31-
@mock.patch("psycopg2.connect")
3287
# pylint: disable=unused-argument
33-
def test_instrumentor(self, mock_connect):
88+
def test_instrumentor(self):
3489
Psycopg2Instrumentor().instrument()
3590

3691
cnx = psycopg2.connect(database="test")
@@ -60,9 +115,39 @@ def test_instrumentor(self, mock_connect):
60115
spans_list = self.memory_exporter.get_finished_spans()
61116
self.assertEqual(len(spans_list), 1)
62117

63-
@mock.patch("psycopg2.connect")
118+
def test_composed(self):
119+
Psycopg2Instrumentor().instrument()
120+
121+
cnx = psycopg2.connect(database="test")
122+
123+
cursor = cnx.cursor()
124+
125+
query = "SELECT * FROM test"
126+
cursor.execute(query)
127+
128+
spans_list = self.memory_exporter.get_finished_spans()
129+
self.assertEqual(len(spans_list), 1)
130+
span = spans_list[0]
131+
132+
# Check version and name in span's instrumentation info
133+
self.check_span_instrumentation_info(
134+
span, opentelemetry.instrumentation.psycopg2
135+
)
136+
137+
# check that no spans are generated after uninstrument
138+
Psycopg2Instrumentor().uninstrument()
139+
140+
cnx = psycopg2.connect(database="test")
141+
cursor = cnx.cursor()
142+
query = "SELECT * FROM test"
143+
cursor.execute(query)
144+
145+
spans_list = self.memory_exporter.get_finished_spans()
146+
self.assertEqual(len(spans_list), 1)
147+
148+
64149
# pylint: disable=unused-argument
65-
def test_not_recording(self, mock_connect):
150+
def test_not_recording(self):
66151
mock_tracer = mock.Mock()
67152
mock_span = mock.Mock()
68153
mock_span.is_recording.return_value = False
@@ -83,9 +168,8 @@ def test_not_recording(self, mock_connect):
83168

84169
Psycopg2Instrumentor().uninstrument()
85170

86-
@mock.patch("psycopg2.connect")
87171
# pylint: disable=unused-argument
88-
def test_custom_tracer_provider(self, mock_connect):
172+
def test_custom_tracer_provider(self):
89173
resource = resources.Resource.create({})
90174
result = self.create_tracer_provider(resource=resource)
91175
tracer_provider, exporter = result
@@ -103,9 +187,8 @@ def test_custom_tracer_provider(self, mock_connect):
103187

104188
self.assertIs(span.resource, resource)
105189

106-
@mock.patch("psycopg2.connect")
107190
# pylint: disable=unused-argument
108-
def test_instrument_connection(self, mock_connect):
191+
def test_instrument_connection(self):
109192
cnx = psycopg2.connect(database="test")
110193
query = "SELECT * FROM test"
111194
cursor = cnx.cursor()
@@ -121,9 +204,8 @@ def test_instrument_connection(self, mock_connect):
121204
spans_list = self.memory_exporter.get_finished_spans()
122205
self.assertEqual(len(spans_list), 1)
123206

124-
@mock.patch("psycopg2.connect")
125207
# pylint: disable=unused-argument
126-
def test_uninstrument_connection(self, mock_connect):
208+
def test_uninstrument_connection(self):
127209
Psycopg2Instrumentor().instrument()
128210
cnx = psycopg2.connect(database="test")
129211
query = "SELECT * FROM test"

‎instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ def test_execute(self):
6060
stmt = "CREATE TABLE IF NOT EXISTS test (id integer)"
6161
with self._tracer.start_as_current_span("rootSpan"):
6262
self._cursor.execute(stmt)
63-
self.validate_spans(stmt)
63+
self.validate_spans("CREATE")
6464

6565
def test_executemany(self):
6666
"""Should create a child span for executemany"""
6767
stmt = "INSERT INTO test (id) VALUES (?)"
6868
with self._tracer.start_as_current_span("rootSpan"):
6969
data = [("1",), ("2",), ("3",)]
7070
self._cursor.executemany(stmt, data)
71-
self.validate_spans(stmt)
71+
self.validate_spans("INSERT")
7272

7373
def test_callproc(self):
7474
"""Should create a child span for callproc"""

‎tests/opentelemetry-docker-tests/tests/mysql/test_mysql_functional.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_execute(self):
8181
stmt = "CREATE TABLE IF NOT EXISTS test (id INT)"
8282
with self._tracer.start_as_current_span("rootSpan"):
8383
self._cursor.execute(stmt)
84-
self.validate_spans(stmt)
84+
self.validate_spans("CREATE")
8585

8686
def test_execute_with_connection_context_manager(self):
8787
"""Should create a child span for execute with connection context"""
@@ -90,23 +90,23 @@ def test_execute_with_connection_context_manager(self):
9090
with self._connection as conn:
9191
cursor = conn.cursor()
9292
cursor.execute(stmt)
93-
self.validate_spans(stmt)
93+
self.validate_spans("CREATE")
9494

9595
def test_execute_with_cursor_context_manager(self):
9696
"""Should create a child span for execute with cursor context"""
9797
stmt = "CREATE TABLE IF NOT EXISTS test (id INT)"
9898
with self._tracer.start_as_current_span("rootSpan"):
9999
with self._connection.cursor() as cursor:
100100
cursor.execute(stmt)
101-
self.validate_spans(stmt)
101+
self.validate_spans("CREATE")
102102

103103
def test_executemany(self):
104104
"""Should create a child span for executemany"""
105105
stmt = "INSERT INTO test (id) VALUES (%s)"
106106
with self._tracer.start_as_current_span("rootSpan"):
107107
data = (("1",), ("2",), ("3",))
108108
self._cursor.executemany(stmt, data)
109-
self.validate_spans(stmt)
109+
self.validate_spans("INSERT")
110110

111111
def test_callproc(self):
112112
"""Should create a child span for callproc"""

‎tests/opentelemetry-docker-tests/tests/postgres/test_aiopg_functional.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def test_execute(self):
8989
stmt = "CREATE TABLE IF NOT EXISTS test (id integer)"
9090
with self._tracer.start_as_current_span("rootSpan"):
9191
async_call(self._cursor.execute(stmt))
92-
self.validate_spans(stmt)
92+
self.validate_spans("CREATE")
9393

9494
def test_executemany(self):
9595
"""Should create a child span for executemany"""
@@ -98,7 +98,7 @@ def test_executemany(self):
9898
with self._tracer.start_as_current_span("rootSpan"):
9999
data = (("1",), ("2",), ("3",))
100100
async_call(self._cursor.executemany(stmt, data))
101-
self.validate_spans(stmt)
101+
self.validate_spans("INSERT")
102102

103103
def test_callproc(self):
104104
"""Should create a child span for callproc"""
@@ -167,7 +167,7 @@ def test_execute(self):
167167
stmt = "CREATE TABLE IF NOT EXISTS test (id integer)"
168168
with self._tracer.start_as_current_span("rootSpan"):
169169
async_call(self._cursor.execute(stmt))
170-
self.validate_spans(stmt)
170+
self.validate_spans("CREATE")
171171

172172
def test_executemany(self):
173173
"""Should create a child span for executemany"""
@@ -176,7 +176,7 @@ def test_executemany(self):
176176
with self._tracer.start_as_current_span("rootSpan"):
177177
data = (("1",), ("2",), ("3",))
178178
async_call(self._cursor.executemany(stmt, data))
179-
self.validate_spans(stmt)
179+
self.validate_spans("INSERT")
180180

181181
def test_callproc(self):
182182
"""Should create a child span for callproc"""

‎tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_execute(self):
8181
stmt = "CREATE TABLE IF NOT EXISTS test (id integer)"
8282
with self._tracer.start_as_current_span("rootSpan"):
8383
self._cursor.execute(stmt)
84-
self.validate_spans(stmt)
84+
self.validate_spans("CREATE")
8585

8686
def test_execute_with_connection_context_manager(self):
8787
"""Should create a child span for execute with connection context"""
@@ -90,15 +90,15 @@ def test_execute_with_connection_context_manager(self):
9090
with self._connection as conn:
9191
cursor = conn.cursor()
9292
cursor.execute(stmt)
93-
self.validate_spans(stmt)
93+
self.validate_spans("CREATE")
9494

9595
def test_execute_with_cursor_context_manager(self):
9696
"""Should create a child span for execute with cursor context"""
9797
stmt = "CREATE TABLE IF NOT EXISTS test (id INT)"
9898
with self._tracer.start_as_current_span("rootSpan"):
9999
with self._connection.cursor() as cursor:
100100
cursor.execute(stmt)
101-
self.validate_spans(stmt)
101+
self.validate_spans("CREATE")
102102
self.assertTrue(cursor.closed)
103103

104104
def test_executemany(self):
@@ -107,7 +107,7 @@ def test_executemany(self):
107107
with self._tracer.start_as_current_span("rootSpan"):
108108
data = (("1",), ("2",), ("3",))
109109
self._cursor.executemany(stmt, data)
110-
self.validate_spans(stmt)
110+
self.validate_spans("INSERT")
111111

112112
def test_callproc(self):
113113
"""Should create a child span for callproc"""

‎tests/opentelemetry-docker-tests/tests/pymysql/test_pymysql_functional.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,23 @@ def test_execute(self):
7878
stmt = "CREATE TABLE IF NOT EXISTS test (id INT)"
7979
with self._tracer.start_as_current_span("rootSpan"):
8080
self._cursor.execute(stmt)
81-
self.validate_spans(stmt)
81+
self.validate_spans("CREATE")
8282

8383
def test_execute_with_cursor_context_manager(self):
8484
"""Should create a child span for execute with cursor context"""
8585
stmt = "CREATE TABLE IF NOT EXISTS test (id INT)"
8686
with self._tracer.start_as_current_span("rootSpan"):
8787
with self._connection.cursor() as cursor:
8888
cursor.execute(stmt)
89-
self.validate_spans(stmt)
89+
self.validate_spans("CREATE")
9090

9191
def test_executemany(self):
9292
"""Should create a child span for executemany"""
9393
stmt = "INSERT INTO test (id) VALUES (%s)"
9494
with self._tracer.start_as_current_span("rootSpan"):
9595
data = (("1",), ("2",), ("3",))
9696
self._cursor.executemany(stmt, data)
97-
self.validate_spans(stmt)
97+
self.validate_spans("INSERT")
9898

9999
def test_callproc(self):
100100
"""Should create a child span for callproc"""

0 commit comments

Comments
 (0)
Please sign in to comment.