Skip to content

Commit 80c62ed

Browse files
committed
Add sql.instance attribute to default attributes only if it has non-empty value
1 parent 7d88d38 commit 80c62ed

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

driver_go1.10.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,20 @@ var (
2121
// WrapConnector allows wrapping a database driver.Connector which eliminates
2222
// the need to register ocsql as an available driver.Driver.
2323
func WrapConnector(dc driver.Connector, options ...TraceOption) driver.Connector {
24-
opts := TraceOptions{
25-
InstanceName: defaultInstanceName,
24+
o := TraceOptions{}
25+
for _, option := range options {
26+
option(&o)
2627
}
27-
for _, o := range options {
28-
o(&opts)
28+
if o.InstanceName == "" {
29+
o.InstanceName = defaultInstanceName
30+
} else {
31+
o.DefaultAttributes = append(o.DefaultAttributes, trace.StringAttribute("sql.instance", o.InstanceName))
2932
}
30-
opts.DefaultAttributes = append(
31-
opts.DefaultAttributes,
32-
trace.StringAttribute("sql.instance", opts.InstanceName),
33-
)
3433

3534
return &ocDriver{
3635
parent: dc.Driver(),
3736
connector: dc,
38-
options: opts,
37+
options: o,
3938
}
4039
}
4140

0 commit comments

Comments
 (0)