Skip to content

Set the db.driver.name on Django database queries #6081

Open

Description

@ericapisani

Getting this information is a bit more involved, so separated this from PY-2376 to tackle as a separate set of changes

Activity

  1. linear-code commented on Apr 15, 2026

    @linear-code
  2. self-assigned this
    on Apr 15, 2026
  3. removed their assignment
    on Apr 16, 2026
  4. IgorGanapolsky commented on Jul 24, 2026

    @IgorGanapolsky
  5. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jul 24, 2026
  6. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jul 27, 2026
  7. safina57 commented on Sep 5, 2026

    @safina57
    Contributor

    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)?

  8. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Sep 5, 2026
  9. conka8 commented on Oct 21, 2026

    @conka8

    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?

  10. Pavanpuli89 commented on Nov 10, 2026

    @Pavanpuli89

    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:

    1. 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.
    2. 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.

  11. ADAMAMZAR commented on Nov 24, 2026

    @ADAMAMZAR

    @ericapisani one data point on the naming question raised above, since it seems to be what's blocking this.

    #6082 currently uses two conventions:

    • 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:

    1. Map Django's module names to SQLAlchemy's identifiers (small lookup table, e.g. sqlite3 → pysqlite, MySQLdb → mysqldb), so both integrations agree
    2. Use package names everywhere and revisit SQLAlchemy

    Happy to help with whichever direction you prefer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions