You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Set the db.driver.name on Django database queries #6081
Hi @ericapisani ! I'd like to take this one
my plan is to extend _set_db_data() to also set SPANDATA.DB_DRIVER_NAME, derived from the backend's DBAPI module (db.Database.__name__, normalized to the top-level module). That should covers psycopg2/psycopg, MySQLdb/pymysql, cx_Oracle/oracledb, and sqlite3, guarded with getattr + try/except so custom backends can't break span creation.
one question though, should the value be the raw module name (MySQLdb) or normalized (mysqlclient)?
I'd like to work on this. I'd set db.driver.name on the Django integration's database query spans from the DB-API driver behind each Django connection, with tests on more than one backend (for example SQLite and PostgreSQL) asserting the value. It's labeled "Waiting for: Product Owner", so is it ready to pick up, and should the values follow the same naming as the other database integrations from PY-2376?
Hi @ericapisani, I'd like to work on this and already have a small working implementation with tests (not opened as a PR yet, per the discussion-first guidance).
Approach: in _set_db_data() (Django integration), set db.driver.name from the connection's DB-API module (db.Database.__name__, top-level module only), guarded with try/except so custom backends without a usable Database attribute can't break span creation. That gives psycopg2, psycopg, MySQLdb, sqlite3, etc., which matches how the SQLAlchemy integration reports the driver. Tests cover the value for several driver module names plus the missing-driver case.
Questions:
Raw module name (MySQLdb) or a normalized package name (mysqlclient)? This is the open question above, and I'll follow whatever the PY-2376 convention is.
Two other people have already offered to take this. Who should pick it up? Happy to open the PR right away, or step aside.
Disclosure: I used Claude Code to help draft this; I'll review and test everything myself before opening any PR.
Hardcoded integrations use package names: redis-py, clickhouse-driver, asyncpg, pymongo
SQLAlchemy uses conn.dialect.driver
I checked the db.Database.__name__ approach proposed above against SQLAlchemy 2.1.9 / Django 6.1.3. It lines up for some backends but not others:
Backend
SQLAlchemy dialect.driver
Django Database.__name__
psycopg2
psycopg2
psycopg2
psycopg 3
psycopg
psycopg
oracledb
oracledb
oracledb
sqlite3
pysqlite
sqlite3.dbapi2
mysqlclient
mysqldb
MySQLdb
So with that approach, the same SQLite or MySQL database would show a different db.driver.name depending on whether the query went through Django or SQLAlchemy. Options:
Map Django's module names to SQLAlchemy's identifiers (small lookup table, e.g. sqlite3 → pysqlite, MySQLdb → mysqldb), so both integrations agree
Use package names everywhere and revisit SQLAlchemy
Happy to help with whichever direction you prefer.
Activity
linear-code commentedon Apr 15, 2026
PY-2377
feat: Add `db.driver.name` spans to database integrations
feat: Add `db.driver.name` spans to database integrations (#6082)
IgorGanapolsky commentedon Jul 24, 2026
feat: Add `db.driver.name` spans to database integrations (getsentry#…
safina57 commentedon Sep 5, 2026
Hi @ericapisani ! I'd like to take this one
my plan is to extend
_set_db_data()to also setSPANDATA.DB_DRIVER_NAME, derived from the backend's DBAPI module (db.Database.__name__, normalized to the top-level module). That should covers psycopg2/psycopg, MySQLdb/pymysql, cx_Oracle/oracledb, and sqlite3, guarded with getattr + try/except so custom backends can't break span creation.one question though, should the value be the raw module name (
MySQLdb) or normalized (mysqlclient)?conka8 commentedon Oct 21, 2026
I'd like to work on this. I'd set
db.driver.nameon the Django integration's database query spans from the DB-API driver behind each Django connection, with tests on more than one backend (for example SQLite and PostgreSQL) asserting the value. It's labeled "Waiting for: Product Owner", so is it ready to pick up, and should the values follow the same naming as the other database integrations from PY-2376?Pavanpuli89 commentedon Nov 10, 2026
Hi @ericapisani, I'd like to work on this and already have a small working implementation with tests (not opened as a PR yet, per the discussion-first guidance).
Approach: in
_set_db_data()(Django integration), setdb.driver.namefrom the connection's DB-API module (db.Database.__name__, top-level module only), guarded with try/except so custom backends without a usableDatabaseattribute can't break span creation. That givespsycopg2,psycopg,MySQLdb,sqlite3, etc., which matches how the SQLAlchemy integration reports the driver. Tests cover the value for several driver module names plus the missing-driver case.Questions:
MySQLdb) or a normalized package name (mysqlclient)? This is the open question above, and I'll follow whatever the PY-2376 convention is.Disclosure: I used Claude Code to help draft this; I'll review and test everything myself before opening any PR.
ADAMAMZAR commentedon Nov 24, 2026
@ericapisani one data point on the naming question raised above, since it seems to be what's blocking this.
#6082 currently uses two conventions:
redis-py,clickhouse-driver,asyncpg,pymongoconn.dialect.driverI checked the
db.Database.__name__approach proposed above against SQLAlchemy 2.1.9 / Django 6.1.3. It lines up for some backends but not others:dialect.driverDatabase.__name__psycopg2psycopg2psycopgpsycopgoracledboracledbpysqlitesqlite3.dbapi2mysqldbMySQLdbSo with that approach, the same SQLite or MySQL database would show a different
db.driver.namedepending on whether the query went through Django or SQLAlchemy. Options:sqlite3→pysqlite,MySQLdb→mysqldb), so both integrations agreeHappy to help with whichever direction you prefer.