Skip to content

Commit 0efbc16

Browse files
authored
mysql: use otelsql.OpenDB to wrap the connector (#3631)
1 parent bc60307 commit 0efbc16

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

mysql/mysql.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package mysql
1818
import (
1919
"context"
2020
"database/sql"
21-
"database/sql/driver"
2221
"fmt"
2322
"net/url"
2423
"regexp"
@@ -49,10 +48,11 @@ func (uo *URLOpener) OpenMySQLURL(_ context.Context, u *url.URL) (*sql.DB, error
4948
if err != nil {
5049
return nil, err
5150
}
52-
return sql.OpenDB(connector{
53-
dsn: cfg.FormatDSN(),
54-
traceOpts: append([]otelsql.Option(nil), uo.TraceOpts...),
55-
}), nil
51+
c, err := mysql.NewConnector(cfg)
52+
if err != nil {
53+
return nil, fmt.Errorf("mysql: could not create connector: %v", err)
54+
}
55+
return otelsql.OpenDB(c, uo.TraceOpts...), nil
5656
}
5757

5858
var netAddrRE = regexp.MustCompile(`^(.+)\((.+)\)$`)
@@ -83,19 +83,6 @@ func ConfigFromURL(u *url.URL) (cfg *mysql.Config, err error) {
8383
return cfg, nil
8484
}
8585

86-
type connector struct {
87-
dsn string
88-
traceOpts []otelsql.Option
89-
}
90-
91-
func (c connector) Connect(context.Context) (driver.Conn, error) {
92-
return c.Driver().Open(c.dsn)
93-
}
94-
95-
func (c connector) Driver() driver.Driver {
96-
return otelsql.WrapDriver(mysql.MySQLDriver{}, c.traceOpts...)
97-
}
98-
9986
// MySQLURLOpener implements MySQLURLOpener and can open connections based on a URL.
10087
// The opener must not modify the URL argument. OpenMySQLURL must be safe to
10188
// call from multiple goroutines.

0 commit comments

Comments
 (0)