diff --git a/.github/workflows/check-codegen.yml b/.github/workflows/check-codegen.yml index 6ef0f1ed1..0ee6bd406 100644 --- a/.github/workflows/check-codegen.yml +++ b/.github/workflows/check-codegen.yml @@ -32,6 +32,7 @@ jobs: - name: Build run: | go install ./internal/cmd/gtrace + go install ./internal/cmd/gstack go install go.uber.org/mock/mockgen@v0.4.0 - name: Clean and re-generate *_gtrace.go files @@ -40,5 +41,9 @@ jobs: go generate ./trace go generate ./... + - name: Re-generate stack.FunctionID calls + run: | + gstack . + - name: Check repository diff run: bash ./.github/scripts/check-work-copy-equals-to-committed.sh "code-generation not equal with committed" diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bbe725aa..740b707de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +* Added internal `gstack` codegen tool for filling `stack.FunctionID` with value from call stack + ## v3.59.1 * Fixed updating last usage timestamp for smart parking of the conns diff --git a/driver.go b/driver.go index 795251dec..ea0d8c521 100644 --- a/driver.go +++ b/driver.go @@ -115,7 +115,8 @@ func (d *Driver) trace() *trace.Driver { // //nolint:nonamedreturns func (d *Driver) Close(ctx context.Context) (finalErr error) { - onDone := trace.DriverOnClose(d.trace(), &ctx, stack.FunctionID("")) + onDone := trace.DriverOnClose(d.trace(), &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/ydb.(*Driver).Close")) defer func() { onDone(finalErr) }() @@ -248,7 +249,7 @@ func Open(ctx context.Context, dsn string, opts ...Option) (_ *Driver, err error onDone := trace.DriverOnInit( d.trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/ydb.Open"), d.config.Endpoint(), d.config.Database(), d.config.Secure(), ) defer func() { @@ -284,7 +285,7 @@ func New(ctx context.Context, opts ...Option) (_ *Driver, err error) { onDone := trace.DriverOnInit( d.trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/ydb.New"), d.config.Endpoint(), d.config.Database(), d.config.Secure(), ) defer func() { diff --git a/internal/balancer/balancer.go b/internal/balancer/balancer.go index 7a67c27db..f69ec11e2 100644 --- a/internal/balancer/balancer.go +++ b/internal/balancer/balancer.go @@ -97,7 +97,8 @@ func (b *Balancer) clusterDiscoveryAttempt(ctx context.Context) (err error) { address = "ydb:///" + b.driverConfig.Endpoint() onDone = trace.DriverOnBalancerClusterDiscoveryAttempt( b.driverConfig.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID( + "github.com/ydb-platform/ydb-go-sdk/3/internal/balancer.(*Balancer).clusterDiscoveryAttempt"), address, ) endpoints []endpoint.Endpoint @@ -173,7 +174,8 @@ func (b *Balancer) applyDiscoveredEndpoints(ctx context.Context, endpoints []end var ( onDone = trace.DriverOnBalancerUpdate( b.driverConfig.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID( + "github.com/ydb-platform/ydb-go-sdk/3/internal/balancer.(*Balancer).applyDiscoveredEndpoints"), b.config.DetectLocalDC, ) previousConns []conn.Conn @@ -211,7 +213,7 @@ func (b *Balancer) applyDiscoveredEndpoints(ctx context.Context, endpoints []end func (b *Balancer) Close(ctx context.Context) (err error) { onDone := trace.DriverOnBalancerClose( b.driverConfig.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/balancer.(*Balancer).Close"), ) defer func() { onDone(err) @@ -237,7 +239,7 @@ func New( var ( onDone = trace.DriverOnBalancerInit( driverConfig.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/balancer.New"), driverConfig.Balancer().String(), ) discoveryConfig = discoveryConfig.New(append(opts, @@ -371,7 +373,7 @@ func (b *Balancer) connections() *connectionsState { func (b *Balancer) getConn(ctx context.Context) (c conn.Conn, err error) { onDone := trace.DriverOnBalancerChooseEndpoint( b.driverConfig.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/balancer.(*Balancer).getConn"), ) defer func() { if err == nil { diff --git a/internal/cmd/gstack/main.go b/internal/cmd/gstack/main.go new file mode 100644 index 000000000..6893d57f9 --- /dev/null +++ b/internal/cmd/gstack/main.go @@ -0,0 +1,227 @@ +package main + +import ( + "bytes" + "flag" + "fmt" + "go/ast" + "go/parser" + "go/token" + "io/fs" + "os" + "path/filepath" + + "github.com/ydb-platform/ydb-go-sdk/v3/internal/cmd/gstack/utils" +) + +func usage() { + fmt.Fprintf(os.Stderr, "usage: gstack [path]\n") + flag.PrintDefaults() +} + +func getCallExpressionsFromExpr(expr ast.Expr) (listOfCalls []*ast.CallExpr) { + switch expr := expr.(type) { + case *ast.SelectorExpr: + listOfCalls = getCallExpressionsFromExpr(expr.X) + case *ast.IndexExpr: + listOfCalls = getCallExpressionsFromExpr(expr.X) + case *ast.StarExpr: + listOfCalls = getCallExpressionsFromExpr(expr.X) + case *ast.BinaryExpr: + listOfCalls = getCallExpressionsFromExpr(expr.X) + listOfCalls = append(listOfCalls, getCallExpressionsFromExpr(expr.Y)...) + case *ast.CallExpr: + listOfCalls = append(listOfCalls, expr) + listOfCalls = append(listOfCalls, getCallExpressionsFromExpr(expr.Fun)...) + for _, arg := range expr.Args { + listOfCalls = append(listOfCalls, getCallExpressionsFromExpr(arg)...) + } + case *ast.CompositeLit: + for _, elt := range expr.Elts { + listOfCalls = append(listOfCalls, getCallExpressionsFromExpr(elt)...) + } + case *ast.UnaryExpr: + listOfCalls = append(listOfCalls, getCallExpressionsFromExpr(expr.X)...) + case *ast.KeyValueExpr: + listOfCalls = append(listOfCalls, getCallExpressionsFromExpr(expr.Value)...) + case *ast.FuncLit: + listOfCalls = append(listOfCalls, getListOfCallExpressionsFromBlockStmt(expr.Body)...) + } + + return listOfCalls +} + +func getExprFromDeclStmt(statement *ast.DeclStmt) (listOfExpressions []ast.Expr) { + decl, ok := statement.Decl.(*ast.GenDecl) + if !ok { + return listOfExpressions + } + for _, spec := range decl.Specs { + if spec, ok := spec.(*ast.ValueSpec); ok { + listOfExpressions = append(listOfExpressions, spec.Values...) + } + } + + return listOfExpressions +} + +func getCallExpressionsFromStmt(statement ast.Stmt) (listOfCallExpressions []*ast.CallExpr) { + var body *ast.BlockStmt + var listOfExpressions []ast.Expr + switch stmt := statement.(type) { + case *ast.IfStmt: + body = stmt.Body + case *ast.SwitchStmt: + body = stmt.Body + case *ast.TypeSwitchStmt: + body = stmt.Body + case *ast.SelectStmt: + body = stmt.Body + case *ast.ForStmt: + body = stmt.Body + case *ast.RangeStmt: + body = stmt.Body + case *ast.DeclStmt: + listOfExpressions = append(listOfExpressions, getExprFromDeclStmt(stmt)...) + for _, expr := range listOfExpressions { + listOfCallExpressions = append(listOfCallExpressions, getCallExpressionsFromExpr(expr)...) + } + case *ast.CommClause: + stmts := stmt.Body + for _, stmt := range stmts { + listOfCallExpressions = append(listOfCallExpressions, getCallExpressionsFromStmt(stmt)...) + } + case *ast.ExprStmt: + listOfCallExpressions = append(listOfCallExpressions, getCallExpressionsFromExpr(stmt.X)...) + } + if body != nil { + listOfCallExpressions = append( + listOfCallExpressions, + getListOfCallExpressionsFromBlockStmt(body)..., + ) + } + + return listOfCallExpressions +} + +func getListOfCallExpressionsFromBlockStmt(block *ast.BlockStmt) (listOfCallExpressions []*ast.CallExpr) { + for _, statement := range block.List { + switch expr := statement.(type) { + case *ast.ExprStmt: + listOfCallExpressions = append(listOfCallExpressions, getCallExpressionsFromExpr(expr.X)...) + case *ast.ReturnStmt: + for _, result := range expr.Results { + listOfCallExpressions = append(listOfCallExpressions, getCallExpressionsFromExpr(result)...) + } + case *ast.AssignStmt: + for _, rh := range expr.Rhs { + listOfCallExpressions = append(listOfCallExpressions, getCallExpressionsFromExpr(rh)...) + } + default: + listOfCallExpressions = append(listOfCallExpressions, getCallExpressionsFromStmt(statement)...) + } + } + + return listOfCallExpressions +} + +func format(src []byte, path string, fset *token.FileSet, file *ast.File) ([]byte, error) { + var listOfArgs []utils.FunctionIDArg + for _, f := range file.Decls { + var listOfCalls []*ast.CallExpr + fn, ok := f.(*ast.FuncDecl) + if !ok { + continue + } + listOfCalls = getListOfCallExpressionsFromBlockStmt(fn.Body) + for _, call := range listOfCalls { + if function, ok := call.Fun.(*ast.SelectorExpr); ok && function.Sel.Name == "FunctionID" { + pack, ok := function.X.(*ast.Ident) + if !ok { + continue + } + if pack.Name == "stack" && len(call.Args) == 1 { + listOfArgs = append(listOfArgs, utils.FunctionIDArg{ + FuncDecl: fn, + ArgPos: call.Args[0].Pos(), + ArgEnd: call.Args[0].End(), + }) + } + } + } + } + if len(listOfArgs) != 0 { + fixed, err := utils.FixSource(fset, path, src, listOfArgs) + if err != nil { + return nil, err + } + + return fixed, nil + } + + return src, nil +} + +func processFile(src []byte, path string, fset *token.FileSet, file *ast.File, info os.FileInfo) error { + formatted, err := format(src, path, fset, file) + if err != nil { + return err + } + if !bytes.Equal(src, formatted) { + err = utils.WriteFile(path, formatted, info.Mode().Perm()) + if err != nil { + return err + } + } + + return nil +} + +func main() { + flag.Usage = usage + flag.Parse() + args := flag.Args() + + if len(args) != 1 { + flag.Usage() + + return + } + _, err := os.Stat(args[0]) + if err != nil { + panic(err) + } + + fileSystem := os.DirFS(args[0]) + + err = fs.WalkDir(fileSystem, ".", func(path string, d fs.DirEntry, err error) error { + fset := token.NewFileSet() + if err != nil { + return err + } + if d.IsDir() { + return nil + } + if filepath.Ext(path) == ".go" { + info, err := os.Stat(path) + if err != nil { + return err + } + src, err := utils.ReadFile(path, info) + if err != nil { + return err + } + file, err := parser.ParseFile(fset, path, nil, 0) + if err != nil { + return err + } + + return processFile(src, path, fset, file, info) + } + + return nil + }) + if err != nil { + panic(err) + } +} diff --git a/internal/cmd/gstack/utils/utils.go b/internal/cmd/gstack/utils/utils.go new file mode 100644 index 000000000..19b35512d --- /dev/null +++ b/internal/cmd/gstack/utils/utils.go @@ -0,0 +1,135 @@ +package utils + +import ( + "fmt" + "go/ast" + "go/parser" + "go/token" + "io" + "io/fs" + "os" + "path/filepath" + + "github.com/ydb-platform/ydb-go-sdk/v3/internal/version" +) + +type FunctionIDArg struct { + FuncDecl *ast.FuncDecl + ArgPos token.Pos + ArgEnd token.Pos +} + +func ReadFile(filename string, info fs.FileInfo) ([]byte, error) { + f, err := os.Open(filename) + if err != nil { + return nil, err + } + defer f.Close() + size := int(info.Size()) + src := make([]byte, size) + n, err := io.ReadFull(f, src) + if err != nil { + return nil, err + } + if n < size { + return nil, fmt.Errorf("error: size of %q changed during reading (from %d to %d bytes)", filename, size, n) + } else if n > size { + return nil, fmt.Errorf("error: size of %q changed during reading (from %d to >=%d bytes)", filename, size, len(src)) + } + + return src, nil +} + +func FixSource(fset *token.FileSet, path string, src []byte, listOfArgs []FunctionIDArg) ([]byte, error) { + var fixed []byte + var previousArgEnd int + for _, arg := range listOfArgs { + argPosOffset := fset.Position(arg.ArgPos).Offset + argEndOffset := fset.Position(arg.ArgEnd).Offset + argument, err := makeCall(fset, path, arg) + if err != nil { + return nil, err + } + fixed = append(fixed, src[previousArgEnd:argPosOffset]...) + fixed = append(fixed, fmt.Sprintf("%q", argument)...) + previousArgEnd = argEndOffset + } + fixed = append(fixed, src[previousArgEnd:]...) + + return fixed, nil +} + +func WriteFile(filename string, formatted []byte, perm fs.FileMode) error { + fout, err := os.OpenFile(filename, os.O_WRONLY|os.O_TRUNC, perm) + if err != nil { + return err + } + + defer fout.Close() + + _, err = fout.Write(formatted) + if err != nil { + return err + } + + return nil +} + +func makeCall(fset *token.FileSet, path string, arg FunctionIDArg) (string, error) { + basePath := filepath.Join("github.com", "ydb-platform", version.Prefix, version.Major, "") + packageName, err := getPackageName(fset, arg) + if err != nil { + return "", err + } + filePath := filepath.Dir(filepath.Dir(path)) + funcName, err := getFuncName(arg.FuncDecl) + if err != nil { + return "", err + } + + return filepath.Join(basePath, filePath, packageName) + "." + funcName, nil +} + +func getFuncName(funcDecl *ast.FuncDecl) (string, error) { + if funcDecl.Recv != nil { + recvType := funcDecl.Recv.List[0].Type + prefix, err := getIdentNameFromExpr(recvType) + if err != nil { + return "", err + } + + return prefix + "." + funcDecl.Name.Name, nil + } + + return funcDecl.Name.Name, nil +} + +func getIdentNameFromExpr(expr ast.Expr) (string, error) { + switch expr := expr.(type) { + case *ast.Ident: + return expr.Name, nil + case *ast.StarExpr: + prefix, err := getIdentNameFromExpr(expr.X) + if err != nil { + return "", err + } + + return "(*" + prefix + ")", nil + case *ast.IndexExpr: + return getIdentNameFromExpr(expr.X) + case *ast.IndexListExpr: + return getIdentNameFromExpr(expr.X) + default: + return "", fmt.Errorf("error during getting ident from expr") + } +} + +func getPackageName(fset *token.FileSet, arg FunctionIDArg) (string, error) { + file := fset.File(arg.ArgPos) + parsedFile, err := parser.ParseFile(fset, file.Name(), nil, parser.PackageClauseOnly) + if err != nil { + return "", fmt.Errorf("error during get package name function") + } + + return parsedFile.Name.Name, nil +} diff --git a/internal/conn/conn.go b/internal/conn/conn.go index 33aef1d05..218a79982 100644 --- a/internal/conn/conn.go +++ b/internal/conn/conn.go @@ -106,7 +106,7 @@ func (c *conn) NodeID() uint32 { func (c *conn) park(ctx context.Context) (err error) { onDone := trace.DriverOnConnPark( c.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/conn.(*conn).park"), c.Endpoint(), ) defer func() { @@ -149,7 +149,7 @@ func (c *conn) setState(ctx context.Context, s State) State { if state := State(c.state.Swap(uint32(s))); state != s { trace.DriverOnConnStateChange( c.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/conn.(*conn).setState"), c.endpoint.Copy(), state, )(s) } @@ -197,7 +197,7 @@ func (c *conn) realConn(ctx context.Context) (cc *grpc.ClientConn, err error) { onDone := trace.DriverOnConnDial( c.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/conn.(*conn).realConn"), c.endpoint.Copy(), ) defer func() { @@ -278,7 +278,7 @@ func (c *conn) Close(ctx context.Context) (err error) { onDone := trace.DriverOnConnClose( c.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/conn.(*conn).Close"), c.Endpoint(), ) defer func() { @@ -311,7 +311,7 @@ func (c *conn) Invoke( useWrapping = UseWrapping(ctx) onDone = trace.DriverOnConnInvoke( c.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/conn.(*conn).Invoke"), c.endpoint, trace.Method(method), ) cc *grpc.ClientConn @@ -395,7 +395,7 @@ func (c *conn) NewStream( var ( onDone = trace.DriverOnConnNewStream( c.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/conn.(*conn).NewStream"), c.endpoint.Copy(), trace.Method(method), ) useWrapping = UseWrapping(ctx) diff --git a/internal/conn/grpc_client_stream.go b/internal/conn/grpc_client_stream.go index 8af9e3b15..a91c8b037 100644 --- a/internal/conn/grpc_client_stream.go +++ b/internal/conn/grpc_client_stream.go @@ -25,7 +25,8 @@ type grpcClientStream struct { } func (s *grpcClientStream) CloseSend() (err error) { - onDone := trace.DriverOnConnStreamCloseSend(s.c.config.Trace(), &s.ctx, stack.FunctionID("")) + onDone := trace.DriverOnConnStreamCloseSend(s.c.config.Trace(), &s.ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/conn.(*grpcClientStream).CloseSend")) defer func() { onDone(err) }() @@ -56,7 +57,8 @@ func (s *grpcClientStream) CloseSend() (err error) { } func (s *grpcClientStream) SendMsg(m interface{}) (err error) { - onDone := trace.DriverOnConnStreamSendMsg(s.c.config.Trace(), &s.ctx, stack.FunctionID("")) + onDone := trace.DriverOnConnStreamSendMsg(s.c.config.Trace(), &s.ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/conn.(*grpcClientStream).SendMsg")) defer func() { onDone(err) }() @@ -95,7 +97,8 @@ func (s *grpcClientStream) SendMsg(m interface{}) (err error) { } func (s *grpcClientStream) RecvMsg(m interface{}) (err error) { - onDone := trace.DriverOnConnStreamRecvMsg(s.c.config.Trace(), &s.ctx, stack.FunctionID("")) + onDone := trace.DriverOnConnStreamRecvMsg(s.c.config.Trace(), &s.ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/conn.(*grpcClientStream).RecvMsg")) defer func() { onDone(err) }() diff --git a/internal/conn/pool.go b/internal/conn/pool.go index 36ba04aaa..4c7f5cc02 100644 --- a/internal/conn/pool.go +++ b/internal/conn/pool.go @@ -114,7 +114,7 @@ func (p *Pool) Ban(ctx context.Context, cc Conn, cause error) { trace.DriverOnConnBan( p.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/conn.(*Pool).Ban"), e, cc.GetState(), cause, )(cc.SetState(ctx, Banned)) } @@ -136,7 +136,7 @@ func (p *Pool) Allow(ctx context.Context, cc Conn) { trace.DriverOnConnAllow( p.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/conn.(*Pool).Allow"), e, cc.GetState(), )(cc.Unban(ctx)) } @@ -148,7 +148,8 @@ func (p *Pool) Take(context.Context) error { } func (p *Pool) Release(ctx context.Context) (finalErr error) { - onDone := trace.DriverOnPoolRelease(p.config.Trace(), &ctx, stack.FunctionID("")) + onDone := trace.DriverOnPoolRelease(p.config.Trace(), &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/conn.(*Pool).Release")) defer func() { onDone(finalErr) }() @@ -230,7 +231,8 @@ func (p *Pool) collectConns() []*conn { } func NewPool(ctx context.Context, config Config) *Pool { - onDone := trace.DriverOnPoolNew(config.Trace(), &ctx, stack.FunctionID("")) + onDone := trace.DriverOnPoolNew(config.Trace(), &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/conn.NewPool")) defer onDone() p := &Pool{ diff --git a/internal/discovery/discovery.go b/internal/discovery/discovery.go index 65237078a..33c9d60e5 100644 --- a/internal/discovery/discovery.go +++ b/internal/discovery/discovery.go @@ -40,7 +40,7 @@ func (c *Client) Discover(ctx context.Context) (endpoints []endpoint.Endpoint, e var ( onDone = trace.DiscoveryOnDiscover( c.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/discovery.(*Client).Discover"), c.config.Endpoint(), c.config.Database(), ) request = Ydb_Discovery.ListEndpointsRequest{ @@ -99,7 +99,8 @@ func (c *Client) Discover(ctx context.Context) (endpoints []endpoint.Endpoint, e func (c *Client) WhoAmI(ctx context.Context) (whoAmI *discovery.WhoAmI, err error) { var ( - onDone = trace.DiscoveryOnWhoAmI(c.config.Trace(), &ctx, stack.FunctionID("")) + onDone = trace.DiscoveryOnWhoAmI(c.config.Trace(), &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/discovery.(*Client).WhoAmI")) request = Ydb_Discovery.WhoAmIRequest{} response *Ydb_Discovery.WhoAmIResponse whoAmIResultResult Ydb_Discovery.WhoAmIResult diff --git a/internal/meta/meta.go b/internal/meta/meta.go index 7311f0f38..9419f22c2 100644 --- a/internal/meta/meta.go +++ b/internal/meta/meta.go @@ -115,7 +115,8 @@ func (m *Meta) meta(ctx context.Context) (_ metadata.MD, err error) { var token string - done := trace.DriverOnGetCredentials(m.trace, &ctx, stack.FunctionID("")) + done := trace.DriverOnGetCredentials(m.trace, &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/meta.(*Meta).meta")) defer func() { done(token, err) }() diff --git a/internal/pool/pool.go b/internal/pool/pool.go index e3271af90..b7a5e8a3f 100644 --- a/internal/pool/pool.go +++ b/internal/pool/pool.go @@ -163,7 +163,7 @@ func New[PT Item[T], T any]( onDone := p.trace.OnNew(&NewStartInfo{ Context: &ctx, - Call: stack.FunctionID(""), + Call: stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/pool.New"), }) defer func() { @@ -264,7 +264,7 @@ func (p *Pool[PT, T]) Stats() stats.Stats { func (p *Pool[PT, T]) getItem(ctx context.Context) (_ PT, finalErr error) { onDone := p.trace.OnGet(&GetStartInfo{ Context: &ctx, - Call: stack.FunctionID(""), + Call: stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/pool.(*Pool).getItem"), }) defer func() { onDone(&GetDoneInfo{ @@ -324,7 +324,7 @@ func (p *Pool[PT, T]) getItem(ctx context.Context) (_ PT, finalErr error) { func (p *Pool[PT, T]) putItem(ctx context.Context, item PT) (finalErr error) { onDone := p.trace.OnPut(&PutStartInfo{ Context: &ctx, - Call: stack.FunctionID(""), + Call: stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/pool.(*Pool).putItem"), }) defer func() { onDone(&PutDoneInfo{ @@ -377,7 +377,7 @@ func (p *Pool[PT, T]) closeItem(ctx context.Context, item PT) error { func (p *Pool[PT, T]) try(ctx context.Context, f func(ctx context.Context, item PT) error) (finalErr error) { onDone := p.trace.OnTry(&TryStartInfo{ Context: &ctx, - Call: stack.FunctionID(""), + Call: stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/pool.(*Pool).try"), }) defer func() { onDone(&TryDoneInfo{ @@ -417,7 +417,7 @@ func (p *Pool[PT, T]) With( var ( onDone = p.trace.OnWith(&WithStartInfo{ Context: &ctx, - Call: stack.FunctionID(""), + Call: stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/pool.(*Pool).With"), }) attempts int ) @@ -452,7 +452,7 @@ func (p *Pool[PT, T]) With( func (p *Pool[PT, T]) Close(ctx context.Context) (finalErr error) { onDone := p.trace.OnClose(&CloseStartInfo{ Context: &ctx, - Call: stack.FunctionID(""), + Call: stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/pool.(*Pool).Close"), }) defer func() { onDone(&CloseDoneInfo{ diff --git a/internal/query/client.go b/internal/query/client.go index bdbffb5a1..7acebba36 100644 --- a/internal/query/client.go +++ b/internal/query/client.go @@ -163,7 +163,8 @@ func (c *Client) DoTx(ctx context.Context, op query.TxOperation, opts ...options } func New(ctx context.Context, balancer balancer, cfg *config.Config) *Client { - onDone := trace.QueryOnNew(cfg.Trace(), &ctx, stack.FunctionID("")) + onDone := trace.QueryOnNew(cfg.Trace(), &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/query.New")) defer onDone() client := &Client{ diff --git a/internal/query/result.go b/internal/query/result.go index 9a25da8e7..773af4ee0 100644 --- a/internal/query/result.go +++ b/internal/query/result.go @@ -40,7 +40,8 @@ func newResult( closeResult = func() {} } - onDone := trace.QueryOnResultNew(t, &ctx, stack.FunctionID("")) + onDone := trace.QueryOnResultNew(t, &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/query.newResult")) defer func() { onDone(err) }() @@ -86,7 +87,8 @@ func nextPart( t = &trace.Query{} } - onDone := trace.QueryOnResultNextPart(t, &ctx, stack.FunctionID("")) + onDone := trace.QueryOnResultNextPart(t, &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/query.nextPart")) defer func() { onDone(finalErr) }() @@ -100,7 +102,8 @@ func nextPart( } func (r *result) Close(ctx context.Context) (err error) { - onDone := trace.QueryOnResultClose(r.trace, &ctx, stack.FunctionID("")) + onDone := trace.QueryOnResultClose(r.trace, &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/query.(*result).Close")) defer func() { onDone(err) }() @@ -176,7 +179,8 @@ func (r *result) nextResultSet(ctx context.Context) (_ *resultSet, err error) { } func (r *result) NextResultSet(ctx context.Context) (_ query.ResultSet, err error) { - onDone := trace.QueryOnResultNextResultSet(r.trace, &ctx, stack.FunctionID("")) + onDone := trace.QueryOnResultNextResultSet(r.trace, &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/query.(*result).NextResultSet")) defer func() { onDone(err) }() diff --git a/internal/query/result_set.go b/internal/query/result_set.go index 445cc7050..879bf87d6 100644 --- a/internal/query/result_set.go +++ b/internal/query/result_set.go @@ -85,7 +85,8 @@ func (rs *resultSet) nextRow(ctx context.Context) (*row, error) { } func (rs *resultSet) NextRow(ctx context.Context) (_ query.Row, err error) { - onDone := trace.QueryOnResultSetNextRow(rs.trace, &ctx, stack.FunctionID("")) + onDone := trace.QueryOnResultSetNextRow(rs.trace, &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/query.(*resultSet).NextRow")) defer func() { onDone(err) }() diff --git a/internal/query/row.go b/internal/query/row.go index 27c5cb168..cd7066415 100644 --- a/internal/query/row.go +++ b/internal/query/row.go @@ -35,7 +35,8 @@ func newRow(ctx context.Context, columns []*Ydb.Column, v *Ydb.Value, t *trace.Q } func (r row) Scan(dst ...interface{}) (err error) { - onDone := trace.QueryOnRowScan(r.trace, &r.ctx, stack.FunctionID("")) + onDone := trace.QueryOnRowScan(r.trace, &r.ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/query.row.Scan")) defer func() { onDone(err) }() @@ -44,7 +45,8 @@ func (r row) Scan(dst ...interface{}) (err error) { } func (r row) ScanNamed(dst ...scanner.NamedDestination) (err error) { - onDone := trace.QueryOnRowScanNamed(r.trace, &r.ctx, stack.FunctionID("")) + onDone := trace.QueryOnRowScanNamed(r.trace, &r.ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/query.row.ScanNamed")) defer func() { onDone(err) }() @@ -53,7 +55,8 @@ func (r row) ScanNamed(dst ...scanner.NamedDestination) (err error) { } func (r row) ScanStruct(dst interface{}, opts ...scanner.ScanStructOption) (err error) { - onDone := trace.QueryOnRowScanStruct(r.trace, &r.ctx, stack.FunctionID("")) + onDone := trace.QueryOnRowScanStruct(r.trace, &r.ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/query.row.ScanStruct")) defer func() { onDone(err) }() diff --git a/internal/query/session.go b/internal/query/session.go index 8a487b77e..3ab8f62b5 100644 --- a/internal/query/session.go +++ b/internal/query/session.go @@ -68,7 +68,8 @@ func createSession( opt(s) } - onDone := trace.QueryOnSessionCreate(s.cfg.Trace(), &ctx, stack.FunctionID("")) + onDone := trace.QueryOnSessionCreate(s.cfg.Trace(), &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/query.createSession")) defer func() { onDone(s, finalErr) }() @@ -98,7 +99,8 @@ func createSession( } func (s *Session) attach(ctx context.Context) (finalErr error) { - onDone := trace.QueryOnSessionAttach(s.cfg.Trace(), &ctx, stack.FunctionID(""), s) + onDone := trace.QueryOnSessionAttach(s.cfg.Trace(), &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/query.(*Session).attach"), s) defer func() { onDone(finalErr) }() @@ -189,7 +191,8 @@ func (s *Session) IsAlive() bool { } func (s *Session) Close(ctx context.Context) (err error) { - onDone := trace.QueryOnSessionDelete(s.cfg.Trace(), &ctx, stack.FunctionID(""), s) + onDone := trace.QueryOnSessionDelete(s.cfg.Trace(), &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/query.(*Session).Close"), s) defer func() { onDone(err) }() @@ -230,7 +233,8 @@ func (s *Session) Begin( ) { var tx *transaction - onDone := trace.QueryOnSessionBegin(s.cfg.Trace(), &ctx, stack.FunctionID(""), s) + onDone := trace.QueryOnSessionBegin(s.cfg.Trace(), &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/query.(*Session).Begin"), s) defer func() { onDone(err, tx) }() @@ -267,7 +271,8 @@ func (s *Session) Status() string { func (s *Session) Execute( ctx context.Context, q string, opts ...options.ExecuteOption, ) (_ query.Transaction, _ query.Result, err error) { - onDone := trace.QueryOnSessionExecute(s.cfg.Trace(), &ctx, stack.FunctionID(""), s, q) + onDone := trace.QueryOnSessionExecute(s.cfg.Trace(), &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/query.(*Session).Execute"), s, q) defer func() { onDone(err) }() diff --git a/internal/query/transaction.go b/internal/query/transaction.go index 48262c1ee..fbfcd9151 100644 --- a/internal/query/transaction.go +++ b/internal/query/transaction.go @@ -34,7 +34,8 @@ func (tx transaction) ID() string { func (tx transaction) Execute(ctx context.Context, q string, opts ...options.TxExecuteOption) ( r query.Result, finalErr error, ) { - onDone := trace.QueryOnTxExecute(tx.s.cfg.Trace(), &ctx, stack.FunctionID(""), tx.s, tx, q) + onDone := trace.QueryOnTxExecute(tx.s.cfg.Trace(), &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/query.transaction.Execute"), tx.s, tx, q) defer func() { onDone(finalErr) }() diff --git a/internal/repeater/repeater.go b/internal/repeater/repeater.go index 033b44a14..8cb2fb0c0 100644 --- a/internal/repeater/repeater.go +++ b/internal/repeater/repeater.go @@ -147,7 +147,7 @@ func (r *repeater) wakeUp(ctx context.Context, e Event) (err error) { ctx = WithEvent(ctx, e) onDone := trace.DriverOnRepeaterWakeUp(r.trace, &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/repeater.(*repeater).wakeUp"), r.name, e, ) defer func() { diff --git a/internal/scheme/client.go b/internal/scheme/client.go index 9d0cf10e0..a61e8dcbd 100644 --- a/internal/scheme/client.go +++ b/internal/scheme/client.go @@ -47,7 +47,7 @@ func New(ctx context.Context, cc grpc.ClientConnInterface, config config.Config) func (c *Client) MakeDirectory(ctx context.Context, path string) (finalErr error) { onDone := trace.SchemeOnMakeDirectory(c.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/scheme.(*Client).MakeDirectory"), path, ) defer func() { @@ -86,7 +86,7 @@ func (c *Client) makeDirectory(ctx context.Context, path string) (err error) { func (c *Client) RemoveDirectory(ctx context.Context, path string) (finalErr error) { onDone := trace.SchemeOnRemoveDirectory(c.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/scheme.(*Client).RemoveDirectory"), path, ) defer func() { @@ -124,7 +124,8 @@ func (c *Client) removeDirectory(ctx context.Context, path string) (err error) { } func (c *Client) ListDirectory(ctx context.Context, path string) (d scheme.Directory, finalErr error) { - onDone := trace.SchemeOnListDirectory(c.config.Trace(), &ctx, stack.FunctionID("")) + onDone := trace.SchemeOnListDirectory(c.config.Trace(), &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/scheme.(*Client).ListDirectory")) defer func() { onDone(finalErr) }() @@ -182,7 +183,7 @@ func (c *Client) listDirectory(ctx context.Context, path string) (scheme.Directo func (c *Client) DescribePath(ctx context.Context, path string) (e scheme.Entry, finalErr error) { onDone := trace.SchemeOnDescribePath(c.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/scheme.(*Client).DescribePath"), path, ) defer func() { @@ -243,7 +244,7 @@ func (c *Client) ModifyPermissions( ctx context.Context, path string, opts ...scheme.PermissionsOption, ) (finalErr error) { onDone := trace.SchemeOnModifyPermissions(c.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/scheme.(*Client).ModifyPermissions"), path, ) defer func() { diff --git a/internal/scripting/client.go b/internal/scripting/client.go index 60b85a248..dad4d1774 100644 --- a/internal/scripting/client.go +++ b/internal/scripting/client.go @@ -72,7 +72,7 @@ func (c *Client) execute( ) (r result.Result, err error) { var ( onDone = trace.ScriptingOnExecute(c.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/scripting.(*Client).execute"), query, parameters, ) a = allocator.New() @@ -151,7 +151,7 @@ func (c *Client) explain( ) (e table.ScriptingYQLExplanation, err error) { var ( onDone = trace.ScriptingOnExplain(c.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/scripting.(*Client).explain"), query, ) request = &Ydb_Scripting.ExplainYqlRequest{ @@ -225,7 +225,7 @@ func (c *Client) streamExecute( ) (r result.StreamResult, err error) { var ( onIntermediate = trace.ScriptingOnStreamExecute(c.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/scripting.(*Client).streamExecute"), query, parameters, ) a = allocator.New() @@ -292,7 +292,8 @@ func (c *Client) Close(ctx context.Context) (err error) { if c == nil { return xerrors.WithStackTrace(errNilClient) } - onDone := trace.ScriptingOnClose(c.config.Trace(), &ctx, stack.FunctionID("")) + onDone := trace.ScriptingOnClose(c.config.Trace(), &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/scripting.(*Client).Close")) defer func() { onDone(err) }() diff --git a/internal/stack/function_id_test.go b/internal/stack/function_id_test.go index c913a6d00..f1161fe3d 100644 --- a/internal/stack/function_id_test.go +++ b/internal/stack/function_id_test.go @@ -8,6 +8,8 @@ import ( type genericType[T any] struct{} +type starType struct{} + func (t genericType[T]) Call() string { return FunctionID("").FunctionID() } @@ -16,6 +18,10 @@ func staticCall() string { return FunctionID("").FunctionID() } +func (e *starType) starredCall() string { + return FunctionID("").FunctionID() +} + func TestFunctionIDForGenericType(t *testing.T) { t.Run("StaticFunc", func(t *testing.T) { require.Equal(t, @@ -29,4 +35,11 @@ func TestFunctionIDForGenericType(t *testing.T) { genericType[uint64]{}.Call(), ) }) + t.Run("StarTypeCall", func(t *testing.T) { + x := starType{} + require.Equal(t, + "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack.(*starType).starredCall", + x.starredCall(), + ) + }) } diff --git a/internal/table/client.go b/internal/table/client.go index fe1f91e98..1b077924b 100644 --- a/internal/table/client.go +++ b/internal/table/client.go @@ -35,7 +35,8 @@ type balancer interface { } func New(ctx context.Context, balancer balancer, config *config.Config) *Client { - onDone := trace.TableOnInit(config.Trace(), &ctx, stack.FunctionID("")) + onDone := trace.TableOnInit(config.Trace(), &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.New")) defer func() { onDone(config.SizeLimit()) }() @@ -262,7 +263,9 @@ func (c *Client) CreateSession(ctx context.Context, opts ...table.Option) (_ tab retry.WithIdempotent(true), retry.WithTrace(&trace.Retry{ OnRetry: func(info trace.RetryLoopStartInfo) func(trace.RetryLoopDoneInfo) { - onDone := trace.TableOnCreateSession(c.config.Trace(), info.Context, stack.FunctionID("")) + onDone := trace.TableOnCreateSession(c.config.Trace(), info.Context, + stack.FunctionID( + "github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*Client).CreateSession")) return func(info trace.RetryLoopDoneInfo) { onDone(s, info.Attempts, info.Error) @@ -377,7 +380,8 @@ func (c *Client) internalPoolGet(ctx context.Context, opts ...getOption) (s *ses } } - onDone := trace.TableOnPoolGet(o.t, &ctx, stack.FunctionID("")) + onDone := trace.TableOnPoolGet(o.t, &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*Client).internalPoolGet")) defer func() { onDone(s, i, err) }() @@ -473,7 +477,8 @@ func (c *Client) internalPoolWaitFromCh(ctx context.Context, t *trace.Table) (s el = c.waitQ.PushBack(ch) }) - waitDone := trace.TableOnPoolWait(t, &ctx, stack.FunctionID("")) + waitDone := trace.TableOnPoolWait(t, &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*Client).internalPoolWaitFromCh")) defer func() { waitDone(s, err) @@ -535,7 +540,7 @@ func (c *Client) internalPoolWaitFromCh(ctx context.Context, t *trace.Table) (s // panic. func (c *Client) Put(ctx context.Context, s *session) (err error) { onDone := trace.TableOnPoolPut(c.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*Client).Put"), s, ) defer func() { @@ -640,7 +645,7 @@ func (c *Client) Do(ctx context.Context, op table.Operation, opts ...table.Optio config := c.retryOptions(opts...) attempts, onDone := 0, trace.TableOnDo(config.Trace, &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*Client).Do"), config.Label, config.Idempotent, xcontext.IsNestedCall(ctx), ) defer func() { @@ -669,7 +674,7 @@ func (c *Client) DoTx(ctx context.Context, op table.TxOperation, opts ...table.O config := c.retryOptions(opts...) attempts, onDone := 0, trace.TableOnDoTx(config.Trace, &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*Client).DoTx"), config.Label, config.Idempotent, xcontext.IsNestedCall(ctx), ) defer func() { diff --git a/internal/table/session.go b/internal/table/session.go index 2ebcf3e8e..a5be9d614 100644 --- a/internal/table/session.go +++ b/internal/table/session.go @@ -116,7 +116,8 @@ func (s *session) isClosing() bool { func newSession(ctx context.Context, cc grpc.ClientConnInterface, config *config.Config) ( s *session, err error, ) { - onDone := trace.TableOnSessionNew(config.Trace(), &ctx, stack.FunctionID("")) + onDone := trace.TableOnSessionNew(config.Trace(), &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.newSession")) defer func() { onDone(s, err) }() @@ -179,7 +180,7 @@ func (s *session) Close(ctx context.Context) (err error) { s.closeOnce.Do(func() { onDone := trace.TableOnSessionDelete(s.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*session).Close"), s, ) defer func() { @@ -231,7 +232,7 @@ func (s *session) KeepAlive(ctx context.Context) (err error) { result Ydb_Table.KeepAliveResult onDone = trace.TableOnSessionKeepAlive( s.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*session).KeepAlive"), s, ) ) @@ -613,7 +614,7 @@ func (s *session) Explain( response *Ydb_Table.ExplainDataQueryResponse onDone = trace.TableOnSessionQueryExplain( s.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*session).Explain"), s, query, ) ) @@ -662,7 +663,7 @@ func (s *session) Prepare(ctx context.Context, queryText string) (_ table.Statem result Ydb_Table.PrepareQueryResult onDone = trace.TableOnSessionQueryPrepare( s.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*session).Prepare"), s, queryText, ) ) @@ -745,7 +746,7 @@ func (s *session) Execute( onDone := trace.TableOnSessionQueryExecute( s.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*session).Execute"), s, q, parameters, request.QueryCachePolicy.GetKeepInCache(), ) @@ -985,7 +986,7 @@ func (s *session) StreamReadTable( ) (_ result.StreamResult, err error) { var ( onDone = trace.TableOnSessionQueryStreamRead(s.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*session).StreamReadTable"), s, ) request = Ydb_Table.ReadTableRequest{ @@ -1104,7 +1105,7 @@ func (s *session) StreamExecuteScanQuery( q = queryFromText(query) onDone = trace.TableOnSessionQueryStreamExecute( s.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*session).StreamExecuteScanQuery"), s, q, parameters, ) request = Ydb_Table.ExecuteScanQueryRequest{ @@ -1175,7 +1176,7 @@ func (s *session) BulkUpsert(ctx context.Context, table string, rows value.Value callOptions []grpc.CallOption onDone = trace.TableOnSessionBulkUpsert( s.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*session).BulkUpsert"), s, ) ) @@ -1221,7 +1222,7 @@ func (s *session) BeginTransaction( response *Ydb_Table.BeginTransactionResponse onDone = trace.TableOnTxBegin( s.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*session).BeginTransaction"), s, ) ) diff --git a/internal/table/statement.go b/internal/table/statement.go index c203b36d5..eb797e2ef 100644 --- a/internal/table/statement.go +++ b/internal/table/statement.go @@ -62,7 +62,7 @@ func (s *statement) Execute( onDone := trace.TableOnSessionQueryExecute( s.session.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*statement).Execute"), s.session, s.query, parameters, request.QueryCachePolicy.GetKeepInCache(), ) diff --git a/internal/table/transaction.go b/internal/table/transaction.go index ccf77afe6..a07576196 100644 --- a/internal/table/transaction.go +++ b/internal/table/transaction.go @@ -63,7 +63,7 @@ func (tx *transaction) Execute( ) (r result.Result, err error) { onDone := trace.TableOnTxExecute( tx.s.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*transaction).Execute"), tx.s, tx, queryFromText(query), parameters, ) defer func() { @@ -100,7 +100,7 @@ func (tx *transaction) ExecuteStatement( onDone := trace.TableOnTxExecuteStatement( tx.s.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*transaction).ExecuteStatement"), tx.s, tx, stmt.(*statement).query, parameters, ) defer func() { @@ -133,7 +133,7 @@ func (tx *transaction) CommitTx( ) (r result.Result, err error) { onDone := trace.TableOnTxCommit( tx.s.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*transaction).CommitTx"), tx.s, tx, ) defer func() { @@ -191,7 +191,7 @@ func (tx *transaction) CommitTx( func (tx *transaction) Rollback(ctx context.Context) (err error) { onDone := trace.TableOnTxRollback( tx.s.config.Trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/table.(*transaction).Rollback"), tx.s, tx, ) defer func() { diff --git a/internal/xresolver/xresolver.go b/internal/xresolver/xresolver.go index 5d78a7a55..7eb2046a1 100644 --- a/internal/xresolver/xresolver.go +++ b/internal/xresolver/xresolver.go @@ -33,7 +33,7 @@ func (c *clientConn) Endpoint() string { func (c *clientConn) UpdateState(state resolver.State) (err error) { onDone := trace.DriverOnResolve(c.trace, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xresolver.(*clientConn).UpdateState"), c.Endpoint(), func() (addrs []string) { for i := range state.Addresses { addrs = append(addrs, state.Addresses[i].Addr) diff --git a/internal/xsql/conn.go b/internal/xsql/conn.go index d041abaa2..8f8994b4f 100644 --- a/internal/xsql/conn.go +++ b/internal/xsql/conn.go @@ -155,7 +155,7 @@ func (c *conn) PrepareContext(ctx context.Context, query string) (_ driver.Stmt, return c.currentTx.PrepareContext(ctx, query) } onDone := trace.DatabaseSQLOnConnPrepare(c.trace, &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*conn).PrepareContext"), query, ) defer func() { @@ -198,7 +198,7 @@ func (c *conn) execContext(ctx context.Context, query string, args []driver.Name m = queryModeFromContext(ctx, c.defaultQueryMode) onDone = trace.DatabaseSQLOnConnExec( c.trace, &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*conn).execContext"), query, m.String(), xcontext.IsIdempotent(ctx), c.sinceLastUsage(), ) ) @@ -308,7 +308,7 @@ func (c *conn) queryContext(ctx context.Context, query string, args []driver.Nam m = queryModeFromContext(ctx, c.defaultQueryMode) onDone = trace.DatabaseSQLOnConnQuery( c.trace, &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*conn).queryContext"), query, m.String(), xcontext.IsIdempotent(ctx), c.sinceLastUsage(), ) ) @@ -395,7 +395,8 @@ func (c *conn) queryContext(ctx context.Context, query string, args []driver.Nam } func (c *conn) Ping(ctx context.Context) (finalErr error) { - onDone := trace.DatabaseSQLOnConnPing(c.trace, &ctx, stack.FunctionID("")) + onDone := trace.DatabaseSQLOnConnPing(c.trace, &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*conn).Ping")) defer func() { onDone(finalErr) }() @@ -414,7 +415,7 @@ func (c *conn) Close() (finalErr error) { c.connector.detach(c) onDone := trace.DatabaseSQLOnConnClose( c.trace, &c.openConnCtx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*conn).Close"), ) defer func() { onDone(finalErr) @@ -457,7 +458,8 @@ func (c *conn) ID() string { func (c *conn) BeginTx(ctx context.Context, txOptions driver.TxOptions) (_ driver.Tx, finalErr error) { var tx currentTx - onDone := trace.DatabaseSQLOnConnBegin(c.trace, &ctx, stack.FunctionID("")) + onDone := trace.DatabaseSQLOnConnBegin(c.trace, &ctx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*conn).BeginTx")) defer func() { onDone(tx, finalErr) }() @@ -506,7 +508,7 @@ func (c *conn) Version(_ context.Context) (_ string, _ error) { func (c *conn) IsTableExists(ctx context.Context, tableName string) (tableExists bool, finalErr error) { tableName = c.normalizePath(tableName) onDone := trace.DatabaseSQLOnConnIsTableExists(c.trace, &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*conn).IsTableExists"), tableName, ) defer func() { diff --git a/internal/xsql/connector.go b/internal/xsql/connector.go index a00246969..da43852e9 100644 --- a/internal/xsql/connector.go +++ b/internal/xsql/connector.go @@ -313,7 +313,7 @@ func (c *Connector) Connect(ctx context.Context) (_ driver.Conn, err error) { var ( onDone = trace.DatabaseSQLOnConnectorConnect( c.trace, &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*Connector).Connect"), ) session table.ClosableSession ) diff --git a/internal/xsql/stmt.go b/internal/xsql/stmt.go index 82d80a916..c4b8db149 100644 --- a/internal/xsql/stmt.go +++ b/internal/xsql/stmt.go @@ -31,7 +31,7 @@ var ( func (s *stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (_ driver.Rows, finalErr error) { onDone := trace.DatabaseSQLOnStmtQuery(s.trace, &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*stmt).QueryContext"), s.stmtCtx, s.query, ) defer func() { @@ -50,7 +50,7 @@ func (s *stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (_ dr func (s *stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (_ driver.Result, finalErr error) { onDone := trace.DatabaseSQLOnStmtExec(s.trace, &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*stmt).ExecContext"), s.stmtCtx, s.query, ) defer func() { @@ -72,7 +72,8 @@ func (s *stmt) NumInput() int { } func (s *stmt) Close() (finalErr error) { - onDone := trace.DatabaseSQLOnStmtClose(s.trace, &s.stmtCtx, stack.FunctionID("")) + onDone := trace.DatabaseSQLOnStmtClose(s.trace, &s.stmtCtx, + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*stmt).Close")) defer func() { onDone(finalErr) }() diff --git a/internal/xsql/tx.go b/internal/xsql/tx.go index 0d894c314..d67813437 100644 --- a/internal/xsql/tx.go +++ b/internal/xsql/tx.go @@ -74,7 +74,7 @@ func (tx *tx) checkTxState() error { func (tx *tx) Commit() (finalErr error) { onDone := trace.DatabaseSQLOnTxCommit(tx.conn.trace, &tx.txCtx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*tx).Commit"), tx, ) defer func() { @@ -96,7 +96,7 @@ func (tx *tx) Commit() (finalErr error) { func (tx *tx) Rollback() (finalErr error) { onDone := trace.DatabaseSQLOnTxRollback(tx.conn.trace, &tx.txCtx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*tx).Rollback"), tx, ) defer func() { @@ -120,7 +120,7 @@ func (tx *tx) QueryContext(ctx context.Context, query string, args []driver.Name _ driver.Rows, finalErr error, ) { onDone := trace.DatabaseSQLOnTxQuery(tx.conn.trace, &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*tx).QueryContext"), tx.txCtx, tx, query, ) defer func() { @@ -162,7 +162,7 @@ func (tx *tx) ExecContext(ctx context.Context, query string, args []driver.Named _ driver.Result, finalErr error, ) { onDone := trace.DatabaseSQLOnTxExec(tx.conn.trace, &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*tx).ExecContext"), tx.txCtx, tx, query, ) defer func() { @@ -196,7 +196,7 @@ func (tx *tx) ExecContext(ctx context.Context, query string, args []driver.Named func (tx *tx) PrepareContext(ctx context.Context, query string) (_ driver.Stmt, finalErr error) { onDone := trace.DatabaseSQLOnTxPrepare(tx.conn.trace, &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*tx).PrepareContext"), &tx.txCtx, tx, query, ) defer func() { diff --git a/internal/xsql/tx_fake.go b/internal/xsql/tx_fake.go index 7909bf521..459aba718 100644 --- a/internal/xsql/tx_fake.go +++ b/internal/xsql/tx_fake.go @@ -19,7 +19,7 @@ type txFake struct { func (tx *txFake) PrepareContext(ctx context.Context, query string) (_ driver.Stmt, finalErr error) { onDone := trace.DatabaseSQLOnTxPrepare(tx.conn.trace, &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*txFake).PrepareContext"), &tx.beginCtx, tx, query, ) defer func() { @@ -58,7 +58,7 @@ func (tx *txFake) ID() string { func (tx *txFake) Commit() (err error) { onDone := trace.DatabaseSQLOnTxCommit(tx.conn.trace, &tx.ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*txFake).Commit"), tx, ) defer func() { @@ -76,7 +76,7 @@ func (tx *txFake) Commit() (err error) { func (tx *txFake) Rollback() (err error) { onDone := trace.DatabaseSQLOnTxRollback(tx.conn.trace, &tx.ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*txFake).Rollback"), tx, ) defer func() { @@ -97,7 +97,7 @@ func (tx *txFake) QueryContext(ctx context.Context, query string, args []driver. ) { onDone := trace.DatabaseSQLOnTxQuery( tx.conn.trace, &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*txFake).QueryContext"), tx.ctx, tx, query, ) defer func() { @@ -116,7 +116,7 @@ func (tx *txFake) ExecContext(ctx context.Context, query string, args []driver.N ) { onDone := trace.DatabaseSQLOnTxExec( tx.conn.trace, &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/xsql.(*txFake).ExecContext"), tx.ctx, tx, query, ) defer func() { diff --git a/retry/retry.go b/retry/retry.go index e9520a071..16b1050bf 100644 --- a/retry/retry.go +++ b/retry/retry.go @@ -232,7 +232,7 @@ func WithPanicCallback(panicCallback func(e interface{})) panicCallbackOption { // If you need to retry your op func on some logic errors - you must return RetryableError() from retryOperation func Retry(ctx context.Context, op retryOperation, opts ...Option) (finalErr error) { options := &retryOptions{ - call: stack.FunctionID(""), + call: stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/retry.Retry"), trace: &trace.Retry{}, fastBackoff: backoff.Fast, slowBackoff: backoff.Slow, diff --git a/retry/sql.go b/retry/sql.go index 115b685ad..affde98e2 100644 --- a/retry/sql.go +++ b/retry/sql.go @@ -42,7 +42,7 @@ func Do(ctx context.Context, db *sql.DB, op func(ctx context.Context, cc *sql.Co var ( options = doOptions{ retryOptions: []Option{ - withCaller(stack.FunctionID("")), + withCaller(stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/retry.Do")), }, } attempts = 0 @@ -129,7 +129,7 @@ func DoTx(ctx context.Context, db *sql.DB, op func(context.Context, *sql.Tx) err var ( options = doTxOptions{ retryOptions: []Option{ - withCaller(stack.FunctionID("")), + withCaller(stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/retry.DoTx")), }, txOptions: &sql.TxOptions{ Isolation: sql.LevelDefault, diff --git a/with.go b/with.go index 248ae9435..c226db991 100644 --- a/with.go +++ b/with.go @@ -49,7 +49,7 @@ func (d *Driver) With(ctx context.Context, opts ...Option) (*Driver, error) { onDone := trace.DriverOnWith( d.trace(), &ctx, - stack.FunctionID(""), + stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/ydb.(*Driver).With"), d.config.Endpoint(), d.config.Database(), d.config.Secure(), ) defer func() {