@@ -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.
9090func 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.
114116func 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