Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase the compatibility of Open method #359

Merged
merged 2 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Fixed

- The `Open` method uses the `dataSourceName` when calling `sql.Open`. (#359)

This change improves compatibility with certain drivers that perform a verification of the `dataSourceName` before establishing a connection.

## [0.33.0] - 2024-08-27

### Added
Expand Down Expand Up @@ -214,6 +220,7 @@ This update contains a breaking change of the removal of `SpanOptions.AllowRoot`
### Added

- SpanOptions to suppress creation of spans. (#87, #102)

- `OmitConnResetSession`
- `OmitConnPrepare`
- `OmitConnQuery`
Expand Down
11 changes: 9 additions & 2 deletions sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,15 @@ func WrapDriver(dri driver.Driver, options ...Option) driver.Driver {

// Open is a wrapper over sql.Open with OTel instrumentation.
func Open(driverName, dataSourceName string, options ...Option) (*sql.DB, error) {
// Retrieve the driver implementation we need to wrap with instrumentation
db, err := sql.Open(driverName, "")
// Retrieve the driver implementation we need to wrap with instrumentation.
// The dataSourceName is used to bypass the driver's Open method, as some
// drivers validate the data source name first before actually opening
// connections.
// Any connection opened here (usually no connection will be opened) is not
// used, and it will be closed immediately to prevent leaking connections.
// Usually, no connection will be opened here if the driver implements
// the driver.DriverContext interface.
db, err := sql.Open(driverName, dataSourceName)
if err != nil {
return nil, err
}
Expand Down
Loading