@@ -88,7 +88,9 @@ 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 {}
91+ o := TraceOptions {
92+ InstanceName : defaultInstanceName ,
93+ }
9294 for _ , option := range options {
9395 option (& o )
9496 }
@@ -109,7 +111,9 @@ func (d ocDriver) Open(name string) (driver.Conn, error) {
109111
110112// WrapConn allows an existing driver.Conn to be wrapped by ocsql.
111113func WrapConn (c driver.Conn , options ... TraceOption ) driver.Conn {
112- o := TraceOptions {}
114+ o := TraceOptions {
115+ InstanceName : defaultInstanceName ,
116+ }
113117 for _ , option := range options {
114118 option (& o )
115119 }
@@ -123,7 +127,7 @@ type ocConn struct {
123127}
124128
125129func (c ocConn ) Ping (ctx context.Context ) (err error ) {
126- defer recordCallStats (ctx , "go.sql.ping" )(err )
130+ defer recordCallStats (ctx , "go.sql.ping" , c . options . InstanceName )(err )
127131
128132 if c .options .Ping && (c .options .AllowRoot || trace .FromContext (ctx ) != nil ) {
129133 var span * trace.Span
@@ -151,7 +155,7 @@ func (c ocConn) Ping(ctx context.Context) (err error) {
151155}
152156
153157func (c ocConn ) Exec (query string , args []driver.Value ) (res driver.Result , err error ) {
154- defer recordCallStats (context .Background (), "go.sql.exec" )(err )
158+ defer recordCallStats (context .Background (), "go.sql.exec" , c . options . InstanceName )(err )
155159
156160 if exec , ok := c .parent .(driver.Execer ); ok {
157161 if ! c .options .AllowRoot {
@@ -192,7 +196,7 @@ func (c ocConn) Exec(query string, args []driver.Value) (res driver.Result, err
192196}
193197
194198func (c ocConn ) ExecContext (ctx context.Context , query string , args []driver.NamedValue ) (res driver.Result , err error ) {
195- defer recordCallStats (ctx , "go.sql.exec" )(err )
199+ defer recordCallStats (ctx , "go.sql.exec" , c . options . InstanceName )(err )
196200
197201 if execCtx , ok := c .parent .(driver.ExecerContext ); ok {
198202 parentSpan := trace .FromContext (ctx )
@@ -231,7 +235,7 @@ func (c ocConn) ExecContext(ctx context.Context, query string, args []driver.Nam
231235}
232236
233237func (c ocConn ) Query (query string , args []driver.Value ) (rows driver.Rows , err error ) {
234- defer recordCallStats (context .Background (), "go.sql.query" )(err )
238+ defer recordCallStats (context .Background (), "go.sql.query" , c . options . InstanceName )(err )
235239
236240 if queryer , ok := c .parent .(driver.Queryer ); ok {
237241 if ! c .options .AllowRoot {
@@ -273,7 +277,7 @@ func (c ocConn) Query(query string, args []driver.Value) (rows driver.Rows, err
273277}
274278
275279func (c ocConn ) QueryContext (ctx context.Context , query string , args []driver.NamedValue ) (rows driver.Rows , err error ) {
276- defer recordCallStats (ctx , "go.sql.query" )(err )
280+ defer recordCallStats (ctx , "go.sql.query" , c . options . InstanceName )(err )
277281
278282 if queryerCtx , ok := c .parent .(driver.QueryerContext ); ok {
279283 parentSpan := trace .FromContext (ctx )
@@ -313,7 +317,7 @@ func (c ocConn) QueryContext(ctx context.Context, query string, args []driver.Na
313317}
314318
315319func (c ocConn ) Prepare (query string ) (stmt driver.Stmt , err error ) {
316- defer recordCallStats (context .Background (), "go.sql.prepare" )(err )
320+ defer recordCallStats (context .Background (), "go.sql.prepare" , c . options . InstanceName )(err )
317321
318322 if c .options .AllowRoot {
319323 _ , span := trace .StartSpan (context .Background (), "sql:prepare" , trace .WithSpanKind (trace .SpanKindClient ))
@@ -349,7 +353,7 @@ func (c *ocConn) Begin() (driver.Tx, error) {
349353}
350354
351355func (c * ocConn ) PrepareContext (ctx context.Context , query string ) (stmt driver.Stmt , err error ) {
352- defer recordCallStats (ctx , "go.sql.prepare" )(err )
356+ defer recordCallStats (ctx , "go.sql.prepare" , c . options . InstanceName )(err )
353357
354358 var span * trace.Span
355359 attrs := append ([]trace.Attribute (nil ), c .options .DefaultAttributes ... )
@@ -382,7 +386,7 @@ func (c *ocConn) PrepareContext(ctx context.Context, query string) (stmt driver.
382386}
383387
384388func (c * ocConn ) BeginTx (ctx context.Context , opts driver.TxOptions ) (tx driver.Tx , err error ) {
385- defer recordCallStats (ctx , "go.sql.begin" )(err )
389+ defer recordCallStats (ctx , "go.sql.begin" , c . options . InstanceName )(err )
386390
387391 if ! c .options .AllowRoot && trace .FromContext (ctx ) == nil {
388392 if connBeginTx , ok := c .parent .(driver.ConnBeginTx ); ok {
@@ -479,7 +483,7 @@ type ocStmt struct {
479483}
480484
481485func (s ocStmt ) Exec (args []driver.Value ) (res driver.Result , err error ) {
482- defer recordCallStats (context .Background (), "go.sql.stmt.exec" )(err )
486+ defer recordCallStats (context .Background (), "go.sql.stmt.exec" , s . options . InstanceName )(err )
483487
484488 if ! s .options .AllowRoot {
485489 return s .parent .Exec (args )
@@ -526,7 +530,7 @@ func (s ocStmt) NumInput() int {
526530}
527531
528532func (s ocStmt ) Query (args []driver.Value ) (rows driver.Rows , err error ) {
529- defer recordCallStats (context .Background (), "go.sql.stmt.query" )(err )
533+ defer recordCallStats (context .Background (), "go.sql.stmt.query" , s . options . InstanceName )(err )
530534
531535 if ! s .options .AllowRoot {
532536 return s .parent .Query (args )
@@ -564,7 +568,7 @@ func (s ocStmt) Query(args []driver.Value) (rows driver.Rows, err error) {
564568}
565569
566570func (s ocStmt ) ExecContext (ctx context.Context , args []driver.NamedValue ) (res driver.Result , err error ) {
567- defer recordCallStats (ctx , "go.sql.stmt.exec" )(err )
571+ defer recordCallStats (ctx , "go.sql.stmt.exec" , s . options . InstanceName )(err )
568572
569573 parentSpan := trace .FromContext (ctx )
570574 if ! s .options .AllowRoot && parentSpan == nil {
@@ -603,7 +607,7 @@ func (s ocStmt) ExecContext(ctx context.Context, args []driver.NamedValue) (res
603607}
604608
605609func (s ocStmt ) QueryContext (ctx context.Context , args []driver.NamedValue ) (rows driver.Rows , err error ) {
606- defer recordCallStats (ctx , "go.sql.stmt.query" )(err )
610+ defer recordCallStats (ctx , "go.sql.stmt.query" , s . options . InstanceName )(err )
607611
608612 parentSpan := trace .FromContext (ctx )
609613 if ! s .options .AllowRoot && parentSpan == nil {
@@ -800,7 +804,7 @@ type ocTx struct {
800804}
801805
802806func (t ocTx ) Commit () (err error ) {
803- defer recordCallStats (context .Background (), "go.sql.commit" )(err )
807+ defer recordCallStats (context .Background (), "go.sql.commit" , t . options . InstanceName )(err )
804808
805809 _ , span := trace .StartSpan (t .ctx , "sql:commit" , trace .WithSpanKind (trace .SpanKindClient ))
806810 if len (t .options .DefaultAttributes ) > 0 {
@@ -816,7 +820,7 @@ func (t ocTx) Commit() (err error) {
816820}
817821
818822func (t ocTx ) Rollback () (err error ) {
819- defer recordCallStats (context .Background (), "go.sql.rollback" )(err )
823+ defer recordCallStats (context .Background (), "go.sql.rollback" , t . options . InstanceName )(err )
820824
821825 _ , span := trace .StartSpan (t .ctx , "sql:rollback" , trace .WithSpanKind (trace .SpanKindClient ))
822826 if len (t .options .DefaultAttributes ) > 0 {
0 commit comments