Skip to content

Commit 7d88d38

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

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

driver.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,15 @@ func Register(driverName string, options ...TraceOption) (string, error) {
8888

8989
// Wrap takes a SQL driver and wraps it with OpenCensus instrumentation.
9090
func Wrap(d driver.Driver, options ...TraceOption) driver.Driver {
91-
o := TraceOptions{
92-
InstanceName: defaultInstanceName,
93-
}
91+
o := TraceOptions{}
9492
for _, option := range options {
9593
option(&o)
9694
}
97-
o.DefaultAttributes = append(o.DefaultAttributes, trace.StringAttribute("sql.instance", o.InstanceName))
95+
if o.InstanceName == "" {
96+
o.InstanceName = defaultInstanceName
97+
} else {
98+
o.DefaultAttributes = append(o.DefaultAttributes, trace.StringAttribute("sql.instance", o.InstanceName))
99+
}
98100
if o.QueryParams && !o.Query {
99101
o.QueryParams = false
100102
}
@@ -112,13 +114,15 @@ func (d ocDriver) Open(name string) (driver.Conn, error) {
112114

113115
// WrapConn allows an existing driver.Conn to be wrapped by ocsql.
114116
func WrapConn(c driver.Conn, options ...TraceOption) driver.Conn {
115-
o := TraceOptions{
116-
InstanceName: defaultInstanceName,
117-
}
117+
o := TraceOptions{}
118118
for _, option := range options {
119119
option(&o)
120120
}
121-
o.DefaultAttributes = append(o.DefaultAttributes, trace.StringAttribute("sql.instance", o.InstanceName))
121+
if o.InstanceName == "" {
122+
o.InstanceName = defaultInstanceName
123+
} else {
124+
o.DefaultAttributes = append(o.DefaultAttributes, trace.StringAttribute("sql.instance", o.InstanceName))
125+
}
122126
return wrapConn(c, o)
123127
}
124128

0 commit comments

Comments
 (0)