Skip to content

Commit aa76e4b

Browse files
authored
initializer: add RegisterWithSource to allow pass in dataSourceName to sql.Open (#42)
Adds an initializing function RegisterWithSource that allows the dataSourceName to be passed into database/sql.Open. This option is important for backends such as goracle and godor, lest they return an initialization error. Fixes #41
1 parent 30ed618 commit aa76e4b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

driver.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,18 @@ var (
5252
// It is possible to register multiple wrappers for the same database driver if
5353
// needing different TraceOptions for different connections.
5454
func Register(driverName string, options ...TraceOption) (string, error) {
55+
return RegisterWithSource(driverName, "", options...)
56+
}
57+
58+
// RegisterWithSource initializes and registers our ocsql wrapped database driver
59+
// identified by its driverName, using provided TraceOptions.
60+
// source is useful if some drivers do not accept the empty string when opening the DB.
61+
// On success it returns the generated driverName to use when calling sql.Open.
62+
// It is possible to register multiple wrappers for the same database driver if
63+
// needing different TraceOptions for different connections.
64+
func RegisterWithSource(driverName string, source string, options ...TraceOption) (string, error) {
5565
// retrieve the driver implementation we need to wrap with instrumentation
56-
db, err := sql.Open(driverName, "")
66+
db, err := sql.Open(driverName, source)
5767
if err != nil {
5868
return "", err
5969
}

0 commit comments

Comments
 (0)