|
14 | 14 |
|
15 | 15 |
|
16 | 16 | import logging |
| 17 | +import re |
17 | 18 | from unittest import mock |
18 | 19 |
|
19 | 20 | from opentelemetry import context |
@@ -275,6 +276,42 @@ def test_executemany_comment(self): |
275 | 276 | r"Select 1 /\*dbapi_threadsafety=123,driver_paramstyle='test',libpq_version=123,traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;", |
276 | 277 | ) |
277 | 278 |
|
| 279 | + def test_executemany_comment_matches_db_statement_attribute(self): |
| 280 | + connect_module = mock.MagicMock() |
| 281 | + connect_module.__version__ = mock.MagicMock() |
| 282 | + connect_module.__libpq_version__ = 123 |
| 283 | + connect_module.apilevel = 123 |
| 284 | + connect_module.threadsafety = 123 |
| 285 | + connect_module.paramstyle = "test" |
| 286 | + |
| 287 | + db_integration = dbapi.DatabaseApiIntegration( |
| 288 | + "testname", |
| 289 | + "testcomponent", |
| 290 | + enable_commenter=True, |
| 291 | + commenter_options={"db_driver": False, "dbapi_level": False}, |
| 292 | + connect_module=connect_module, |
| 293 | + ) |
| 294 | + mock_connection = db_integration.wrapped_connection( |
| 295 | + mock_connect, {}, {} |
| 296 | + ) |
| 297 | + cursor = mock_connection.cursor() |
| 298 | + cursor.executemany("Select 1;") |
| 299 | + self.assertRegex( |
| 300 | + cursor.query, |
| 301 | + r"Select 1 /\*dbapi_threadsafety=123,driver_paramstyle='test',libpq_version=123,traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;", |
| 302 | + ) |
| 303 | + spans_list = self.memory_exporter.get_finished_spans() |
| 304 | + self.assertEqual(len(spans_list), 1) |
| 305 | + span = spans_list[0] |
| 306 | + self.assertRegex( |
| 307 | + span.attributes[SpanAttributes.DB_STATEMENT], |
| 308 | + r"Select 1 /\*dbapi_threadsafety=123,driver_paramstyle='test',libpq_version=123,traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/", |
| 309 | + ) |
| 310 | + |
| 311 | + cursor_span_id = re.search(r"[a-zA-Z0-9_]{16}", cursor.query).group() |
| 312 | + db_statement_span_id = re.search(r"[a-zA-Z0-9_]{16}", span.attributes[SpanAttributes.DB_STATEMENT]).group() |
| 313 | + self.assertEqual(cursor_span_id, db_statement_span_id) |
| 314 | + |
278 | 315 | def test_compatible_build_version_psycopg_psycopg2_libpq(self): |
279 | 316 | connect_module = mock.MagicMock() |
280 | 317 | connect_module.__version__ = mock.MagicMock() |
|
0 commit comments