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
Conversation
…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
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #460.
Three DSN formats were silently producing empty
db.name/server.addressattributes:postgres/pgxhost=db.example.com port=5432 dbname=prodmysqluser:pass@tcp:3306/mydbsqlite3file:URI schemefile:test.db?cache=sharedChanges
dsnparsesub-package (pkg/instrumentation/databasesql/dsnparse/) — isolates all parsing logic so it can be compiled and tested without the otelc-injected fields onsql.DB.ParseDSN(driver, dsn string) DSNInfo— driver-dispatched parser returning structured{Host, Port, DBName}. Supportspostgres,pgx,postgresql,mysql,sqlite3,sqlite,sqlserver,mssql,clickhouse,godror,oracle,oci8,go-oci8.key=valueconnection strings (including single-quoted values with backslash escapes).proto(host:port)/dbnameform and the non-standard form without parentheses; Unix socket paths (unix(/tmp/mysql.sock)) return an empty port.DBNamefromfile:URIs,:memory:, and bare filenames/paths.user@host/serviceforms.parse.goinpackage dbis now a thin shim that re-exportsParseDSN,ParseDbName, and the internalLegacyParseDSNshim unchanged.*PreviouslyFailingto document the regression.Test plan
go test -C pkg/instrumentation/databasesql ./dsnparse/...— all tests passdb.nameandserver.addressattributes appear in traces when connecting with each of the three previously-failing DSN formats