Skip to content

feat(databasesql): add DSN parser registry with extensibility and tests.#509

Open
karthik120710 wants to merge 3 commits into
open-telemetry:mainfrom
karthik120710:issue#508
Open

feat(databasesql): add DSN parser registry with extensibility and tests.#509
karthik120710 wants to merge 3 commits into
open-telemetry:mainfrom
karthik120710:issue#508

Conversation

@karthik120710
Copy link
Copy Markdown

Summary

  • Replaced the hardcoded switch in parseDSN with a sync.RWMutex-protected registry of DSNParser functions, making the DSN parsing layer pluggable
    without modifying core code.
  • Added RegisterDSNParser(driverName, parser) as a public API so external drivers and future integrations can register their own parsers (e.g., from
    init()).
  • Registered all previously hardcoded drivers at init() time, including newly added aliases: pgx, lib/pq, sqlserver, oracle, go-oci8, and oci8.
  • Added a bestEffortParse fallback (standard URL parsing) for unrecognized drivers, replacing the prior silent empty-address behavior.
  • Added a Warn log when DSN parsing fails so server.address omission is surfaced rather than silently emitted as "unknown".
  • Expanded DbClientRequestTraceAttrs system-name mapping to cover mariadb, pgx, lib/pq, clickhouse, oracle, and mssql/sqlserver — previously these all
    fell through to other_sql.
  • Bumped go.opentelemetry.io/otel/log, sdk/log, and related packages to v0.19.0.
  • Added a test case for the clickhouse driver system-name mapping and a separate case confirming unknown drivers fall back to other_sql.

Test plan

  • Run go test ./pkg/instrumentation/databasesql/... — all existing and new semconv tests pass.
  • Verify a custom driver can be registered via RegisterDSNParser in an init() and is correctly used at hook time.
  • Confirm that an unregistered driver with a standard URL DSN gets a best-effort address instead of an empty string.
  • Confirm a warning is logged when DSN parsing fails.
    DSN parser lacks extensibility and silently produces empty addresses for unknown drivers #508

- Added a custom DSN parser registration mechanism to support various database drivers.
- Implemented a fallback parsing method for unregistered drivers, improving robustness.
- Updated logging to warn when the server address cannot be determined from the DSN.
- Enhanced test cases to cover new parsing logic and driver mappings.

This change improves the flexibility and reliability of database connection handling.

Signed-off-by: Karthik Rajan <karthikrajanmr@gmail.com>
@karthik120710 karthik120710 requested a review from a team as a code owner May 15, 2026 19:06
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented May 15, 2026

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: karthik120710 / name: Karthik Rajan (b628582)

@github-actions
Copy link
Copy Markdown

The title of this pull request does not match the conventional commits format.
Please update the title, as apprioriate.

Refer to the CONTRIBUTING.md file for more information.

@karthik120710 karthik120710 changed the title replace hardcoded DSN switch with extensible parser registry [instrumentation/databasesql] replace hardcoded DSN switch with extensible parser registry May 16, 2026
@github-actions
Copy link
Copy Markdown

The title of this pull request does not match the conventional commits format.
Please update the title, as apprioriate.

Refer to the CONTRIBUTING.md file for more information.

@karthik120710 karthik120710 changed the title [instrumentation/databasesql] replace hardcoded DSN switch with extensible parser registry fix(instrumentation/databasesql): add pluggable DSN parser registry and expand semconv driver mapping May 16, 2026
@github-actions
Copy link
Copy Markdown

The title of this pull request does not match the conventional commits format.
Please update the title, as apprioriate.

Refer to the CONTRIBUTING.md file for more information.

@karthik120710
Copy link
Copy Markdown
Author

hi @txabman42 i have added pluggable DSN parser registry and expand semconv driver mapping can u review my pr.

@waqar2403
Copy link
Copy Markdown

Hey @karthik120710, nice work a few things I noticed while going through the diff

Build issue: The refactor removes ParseDbName from parse.go but client.go:47 still calls it (dbName := ParseDbName(dataSourceName)). This would fail to compile. Was the removal accidental during the registry refactor?

Test coverage: The new tests cover the semconv mapping changes (clickhouse, unknown driver) but there are no tests for RegisterDSNParser itself, bestEffortParse, or the new aliases like pgx and lib/pq going through parsePostgres. Since the registry is the main change here, a basic test showing registration and lookup works would help.

Minor: The PR title has a leading space which is causing the conventional commit check to fail. Trimming it should fix the CI.

@karthik120710 karthik120710 changed the title fix(instrumentation/databasesql): add pluggable DSN parser registry and expand semconv driver mapping feat(databasesql): add DSN parser registry with extensibility and tests. May 16, 2026
@github-actions github-actions Bot added the scope:feat A new feature being added label May 16, 2026
…verage

- Refactored DSN parsing logic to utilize a dedicated internal package for improved organization and maintainability.
- Renamed functions for consistency and clarity, specifically changing  to .
- Added comprehensive unit tests for the new parsing logic, ensuring robust handling of various DSN formats and edge cases.

This update enhances the overall structure of the codebase and improves the reliability of database connection handling.

Signed-off-by: Karthik Rajan <karthikrajanmr@gmail.com>
@karthik120710
Copy link
Copy Markdown
Author

Hi @waqar2403 I have add units test and updated process title , but still unit test are not running .

@waqar2403
Copy link
Copy Markdown

@karthik120710 good progress on the registry refactoring. Two things here:

Tests not running Your go.mod bumps a few OTel indirect deps (otlploghttp, otel/log, sdk/log) but the go.sum likely needs regeneration. Try this from the module root:

cd pkg/instrumentation/databasesql
go mod tidy
go test ./

If there are still import resolution errors after that, check if testify is listed under require in your go.mod it should already be there from the existing db_test.go usage.

Minor style note on RegisterDSNParse Right now RegisterDSNParser is exposed as a mutable variable

var RegisterDSNParser = dsnparse.RegisterDSNParser

This means any consumer can accidentally overwrite it like db.RegisterDSNParser = nil A simple wrapper function removes that risk

func RegisterDSNParser(driverName string, parser dsnparse.DSNParser) {
    dsnparse.RegisterDSNParser(driverName, parser)
}

Not a blocker just something to consider for safety.
Otherwise the internal/dsnparse package structure, the registry with sync.RWMutex, the BestEffortParse fallback, and the new semconv driver mappings all look good to me.

- Introduced a wrapper function for  to maintain consistency in the registration process.
- This change enhances the clarity of the parser registration mechanism while preserving existing functionality.

This update contributes to better code organization and maintainability in the DSN parsing logic.

Signed-off-by: Karthik Rajan <karthikrajanmr@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope:feat A new feature being added

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants