github.com/instana/go-sensor@v1.62.2-0.20240520081010-4919868049e1/instrumentation_sql_stmt.go (about) 1 // (c) Copyright IBM Corp. 2023 2 3 package instana 4 5 import ( 6 "context" 7 "database/sql/driver" 8 9 otlog "github.com/opentracing/opentracing-go/log" 10 ) 11 12 type wStmt struct { 13 driver.Stmt 14 15 connDetails DbConnDetails 16 query string 17 sensor TracerLogger 18 } 19 20 func (stmt *wStmt) Exec(args []driver.Value) (driver.Result, error) { 21 ctx := context.Background() 22 sp, dbKey := startSQLSpan(ctx, stmt.connDetails, stmt.query, stmt.sensor) 23 defer sp.Finish() 24 25 res, err := stmt.Stmt.Exec(args) //nolint:staticcheck 26 if err != nil && err != driver.ErrSkip { 27 sp.LogFields(otlog.Error(err)) 28 sp.SetTag(dbKey+".error", err.Error()) 29 } 30 31 return res, err 32 } 33 34 func (stmt *wStmt) Query(args []driver.Value) (driver.Rows, error) { 35 ctx := context.Background() 36 sp, dbKey := startSQLSpan(ctx, stmt.connDetails, stmt.query, stmt.sensor) 37 defer sp.Finish() 38 39 res, err := stmt.Stmt.Query(args) //nolint:staticcheck 40 if err != nil && err != driver.ErrSkip { 41 sp.LogFields(otlog.Error(err)) 42 sp.SetTag(dbKey+".error", err.Error()) 43 } 44 45 return res, err 46 }