Add span to UpdateBuilder.ExecContext
This commit is contained in:
parent
7f1c3542b0
commit
3db7e50f1a
1
go.mod
1
go.mod
|
@ -5,4 +5,5 @@ go 1.13
|
|||
require (
|
||||
git.bit5.ru/backend/mysql v1.0.0
|
||||
github.com/stretchr/testify v1.8.1
|
||||
go.opentelemetry.io/otel v1.11.1
|
||||
)
|
||||
|
|
11
go.sum
11
go.sum
|
@ -3,6 +3,13 @@ git.bit5.ru/backend/mysql v1.0.0/go.mod h1:iK3dzIpv9YAGN8Fy6zi1XGUX8R5nl9XQ9NJbw
|
|||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
|
||||
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
|
@ -12,6 +19,10 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
|
|||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
go.opentelemetry.io/otel v1.11.1 h1:4WLLAmcfkmDk2ukNXJyq3/kiz/3UzCaYq6PskJsaou4=
|
||||
go.opentelemetry.io/otel v1.11.1/go.mod h1:1nNhXBbWSD0nsL38H6btgnFN2k4i0sNLHNNMZMSbUGE=
|
||||
go.opentelemetry.io/otel/trace v1.11.1 h1:ofxdnzsNrGBYXbP7t7zpUK281+go5rF7dvdIZXF8gdQ=
|
||||
go.opentelemetry.io/otel/trace v1.11.1/go.mod h1:f/Q9G7vzk5u91PhbmKbg1Qn0rzH1LJ4vbPHFGkTPtOk=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
21
update.go
21
update.go
|
@ -6,8 +6,14 @@ import (
|
|||
"database/sql"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
)
|
||||
|
||||
const tracerName = "git.bit5.ru/backend/dbr"
|
||||
|
||||
var tracer = otel.Tracer(tracerName)
|
||||
|
||||
// UpdateBuilder contains the clauses for an UPDATE statement
|
||||
type UpdateBuilder struct {
|
||||
*Session
|
||||
|
@ -187,12 +193,6 @@ func (b *UpdateBuilder) ToSql() (string, []interface{}) {
|
|||
}
|
||||
|
||||
func (b *UpdateBuilder) Exec() (sql.Result, error) {
|
||||
return b.ExecContext(context.Background())
|
||||
}
|
||||
|
||||
// ExecContext executes the statement represented by the UpdateBuilder
|
||||
// It returns the raw database/sql Result and an error if there was one
|
||||
func (b *UpdateBuilder) ExecContext(ctx context.Context) (sql.Result, error) {
|
||||
sql, args := b.ToSql()
|
||||
|
||||
fullSql, err := Interpolate(sql, args)
|
||||
|
@ -211,3 +211,12 @@ func (b *UpdateBuilder) ExecContext(ctx context.Context) (sql.Result, error) {
|
|||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ExecContext executes the statement represented by the UpdateBuilder
|
||||
// It returns the raw database/sql Result and an error if there was one
|
||||
func (b *UpdateBuilder) ExecContext(ctx context.Context) (sql.Result, error) {
|
||||
_, span := tracer.Start(ctx, "UpdateBuilder.ExecContext")
|
||||
defer span.End()
|
||||
|
||||
return b.Exec()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue