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