Skip to content

Commit 224a771

Browse files
WIP
1 parent 6bb6d38 commit 224a771

File tree

1 file changed

+36
-10
lines changed
  • instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi

1 file changed

+36
-10
lines changed

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

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -427,21 +427,47 @@ def traced_execution(
427427
if args and self._commenter_enabled:
428428
try:
429429
args_list = list(args)
430-
if hasattr(self._connect_module, "__libpq_version__"):
431-
libpq_version = self._connect_module.__libpq_version__
432-
else:
433-
libpq_version = (
434-
self._connect_module.pq.__build_version__
435-
)
436-
430+
db_driver = self._db_api_integration.connect_module.__name__
437431
commenter_data = {
438-
# Psycopg2/framework information
439-
"db_driver": f"psycopg2:{self._connect_module.__version__.split(' ')[0]}",
432+
# TODO MySQLdb attribute
433+
"db_driver": f"{db_driver}:{self._connect_module.__version__.split(' ')[0]}",
440434
"dbapi_threadsafety": self._connect_module.threadsafety,
441435
"dbapi_level": self._connect_module.apilevel,
442-
"libpq_version": libpq_version,
443436
"driver_paramstyle": self._connect_module.paramstyle,
444437
}
438+
439+
if self._db_api_integration.database_system == "postgresql":
440+
if hasattr(self._connect_module, "__libpq_version__"):
441+
libpq_version = self._connect_module.__libpq_version__
442+
else:
443+
libpq_version = (
444+
self._connect_module.pq.__build_version__
445+
)
446+
commenter_data.update(
447+
{
448+
"libpq_version": libpq_version,
449+
}
450+
)
451+
452+
elif self._db_api_integration.database_system == "mysql":
453+
db_driver = self._db_api_integration.connect_module.__name__
454+
455+
mysqlc_version = ""
456+
if db_driver == "mysql.connector":
457+
# TODO Version of mysql.connector not same as mysql C API
458+
mysqlc_version = self._db_api_integration.connect_module.__version__
459+
elif db_driver == "MySQLdb":
460+
# TODO
461+
mysqlc_version = "TODO"
462+
463+
commenter_data.update(
464+
{
465+
"mysqlc_version": mysqlc_version,
466+
}
467+
)
468+
469+
_logger.debug("Using commenter_data: %s", commenter_data)
470+
445471
if self._commenter_options.get(
446472
"opentelemetry_values", True
447473
):

0 commit comments

Comments
 (0)