Generally there are two ways to instrument a Python client-side database driver client framework: instrument() or instrument_connection(). The former seems to be the most-advertised in the docs (e.g. psycopg2, mysqlclient docs) and is also how some distros set up instrumentation (e.g. load_instrumentor). Users can still call instrument_connection() in-code and I'd like to improve this method.
DB-API integration's wrap_connect is used by multiple instrumentors. It accepts connect_module to optionally use for wrapping/unwrapping and populating sqlcomment when opted in.
DB-API integration's instrumentation_connection is called by the instrumentors for mysql-connector, mysqlclient, PyMySQL, and sqlite3. (psycopg2 does it own thing.) Currently this does not accept connect_module. This is needed to better support sqlcommenting by those MySQL driver instrumentors (see also https://github.com/open-telemetry/opentelemetry-python-contrib/issues/2902). Otherwise, sqlcomment will populate with db_driver='unknown%%3Aunknown' -- it doesn't currently because not yet implemented on main.
Describe the solution you'd like
Get DB-API instrument_connection to accept optional connect_module
What problem do you want to solve?
Generally there are two ways to instrument a Python client-side database driver client framework:
instrument()
orinstrument_connection()
. The former seems to be the most-advertised in the docs (e.g. psycopg2, mysqlclient docs) and is also how some distros set up instrumentation (e.g. load_instrumentor). Users can still callinstrument_connection()
in-code and I'd like to improve this method.DB-API integration's wrap_connect is used by multiple instrumentors. It accepts
connect_module
to optionally use for wrapping/unwrapping and populating sqlcomment when opted in.DB-API integration's instrumentation_connection is called by the instrumentors for mysql-connector, mysqlclient, PyMySQL, and sqlite3. (psycopg2 does it own thing.) Currently this does not accept
connect_module
. This is needed to better support sqlcommenting by those MySQL driver instrumentors (see also https://github.com/open-telemetry/opentelemetry-python-contrib/issues/2902). Otherwise, sqlcomment will populate withdb_driver='unknown%%3Aunknown'
-- it doesn't currently because not yet implemented on main.Describe the solution you'd like
Get DB-API
instrument_connection
to accept optionalconnect_module
Describe alternatives you've considered
No response
Additional Context
Relates to https://github.com/open-telemetry/opentelemetry-python-contrib/issues/2902
Would you like to implement a fix?
Yes