Skip to content

Commit

Permalink
Increase the compatibility of Open method (#359)
Browse files Browse the repository at this point in the history
resolve #358
  • Loading branch information
XSAM committed Sep 15, 2024
1 parent f079f75 commit e79ab77
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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

0 comments on commit e79ab77

Please sign in to comment.