Skip to content

fix(databasesql): expand DSN parsing to cover libpq KV, MySQL no-parens, and SQLite URI formats#474

Open
pradhyum6144 wants to merge 1 commit into
open-telemetry:mainfrom
pradhyum6144:fix/databasesql-dsn-parsing
Open

fix(databasesql): expand DSN parsing to cover libpq KV, MySQL no-parens, and SQLite URI formats#474
pradhyum6144 wants to merge 1 commit into
open-telemetry:mainfrom
pradhyum6144:fix/databasesql-dsn-parsing

Conversation

@pradhyum6144
Copy link
Copy Markdown

Summary

Fixes #460.

Three DSN formats were silently producing empty db.name / server.address attributes:

Driver Format Example
postgres / pgx libpq key=value host=db.example.com port=5432 dbname=prod
mysql host not parenthesised user:pass@tcp:3306/mydb
sqlite3 file: URI scheme file:test.db?cache=shared

Changes

  • New dsnparse sub-package (pkg/instrumentation/databasesql/dsnparse/) — isolates all parsing logic so it can be compiled and tested without the otelc-injected fields on sql.DB.
  • ParseDSN(driver, dsn string) DSNInfo — driver-dispatched parser returning structured {Host, Port, DBName}. Supports postgres, pgx, postgresql, mysql, sqlite3, sqlite, sqlserver, mssql, clickhouse, godror, oracle, oci8, go-oci8.
  • PostgreSQL: handles both RFC 3986 URL and libpq key=value connection strings (including single-quoted values with backslash escapes).
  • MySQL: handles both the standard proto(host:port)/dbname form and the non-standard form without parentheses; Unix socket paths (unix(/tmp/mysql.sock)) return an empty port.
  • SQLite: extracts DBName from file: URIs, :memory:, and bare filenames/paths.
  • SQL Server, ClickHouse, Oracle: URL and ADO.NET / user@host/service forms.
  • parse.go in package db is now a thin shim that re-exports ParseDSN, ParseDbName, and the internal LegacyParseDSN shim unchanged.
  • 60+ table-driven tests covering URL, key-value, and edge cases for each driver; three sub-tests are explicitly named *PreviouslyFailing to document the regression.

Test plan

  • go test -C pkg/instrumentation/databasesql ./dsnparse/... — all tests pass
  • Verify db.name and server.address attributes appear in traces when connecting with each of the three previously-failing DSN formats

…ns, and SQLite URI formats

Adds a new dsnparse sub-package with per-driver DSN parsers for
postgres/pgx, mysql, sqlite3, sqlserver, clickhouse, and oracle.
Fixes three previously-silent failures: PostgreSQL libpq key=value
strings, MySQL DSNs without parenthesised host, and SQLite file: URI
schemes. Moves all parse logic out of the otelc-dependent package so
it can be unit-tested independently. Adds 60+ table-driven test cases.

Fixes open-telemetry#460
@pradhyum6144 pradhyum6144 requested a review from a team as a code owner May 7, 2026 18:38
@github-actions github-actions Bot added the scope:fix A bug that is being fixed label May 7, 2026
@txabman42
Copy link
Copy Markdown
Contributor

@pradhyum6144 duplicated, there is already a PR trying to solve #460.

Since you already have context about the problem, feel free to review the other PR and align approaches.

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

Labels

scope:fix A bug that is being fixed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(pkg/instrumentation/databasesql): traces drop server.address for standard DSN formats

2 participants