github.com/instana/go-sensor@v1.62.2-0.20240520081010-4919868049e1/sql_queryer_context.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 wQueryerContext struct {
    13  	driver.QueryerContext
    14  	connDetails DbConnDetails
    15  	sensor      TracerLogger
    16  }
    17  
    18  func (conn *wQueryerContext) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) {
    19  	sp, dbKey := startSQLSpan(ctx, conn.connDetails, query, conn.sensor)
    20  	defer sp.Finish()
    21  
    22  	res, err := conn.QueryerContext.QueryContext(ctx, query, args)
    23  
    24  	if err != nil && err != driver.ErrSkip {
    25  		sp.LogFields(otlog.Error(err))
    26  		sp.SetTag(dbKey+".error", err.Error())
    27  	}
    28  
    29  	return res, err
    30  }