Skip to content

Commit bc60307

Browse files
authored
mysql/gcpmysql: use otelsql.OpenDB to wrap the connector (#3630)
1 parent cc1db3f commit bc60307

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

mysql/gcpmysql/gcpmysql.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ package gcpmysql // import "gocloud.dev/mysql/gcpmysql"
3030
import (
3131
"context"
3232
"database/sql"
33-
"database/sql/driver"
3433
"fmt"
3534
"net/url"
3635
"strings"
@@ -110,9 +109,11 @@ func (uo *URLOpener) OpenMySQLURL(ctx context.Context, u *url.URL) (*sql.DB, err
110109
Certs: uo.CertSource,
111110
}
112111
mysql.RegisterDialContext(dialerName, client.DialContext)
113-
114-
db := sql.OpenDB(connector{cfg.FormatDSN(), uo.TraceOpts})
115-
return db, nil
112+
c, err := mysql.NewConnector(cfg)
113+
if err != nil {
114+
return nil, fmt.Errorf("gcpmysql: open connector %v", err)
115+
}
116+
return otelsql.OpenDB(c, uo.TraceOpts...), nil
116117
}
117118

118119
func configFromURL(u *url.URL, dialerName string) (*mysql.Config, error) {
@@ -159,16 +160,3 @@ func instanceFromURL(u *url.URL) (instance, db string, _ error) {
159160
}
160161

161162
var dialerCounter uint32
162-
163-
type connector struct {
164-
dsn string
165-
traceOpts []otelsql.Option
166-
}
167-
168-
func (c connector) Connect(ctx context.Context) (driver.Conn, error) {
169-
return c.Driver().Open(c.dsn)
170-
}
171-
172-
func (c connector) Driver() driver.Driver {
173-
return otelsql.WrapDriver(mysql.MySQLDriver{}, c.traceOpts...)
174-
}

0 commit comments

Comments
 (0)