diff --git a/database/gdb/gdb_core_transaction.go b/database/gdb/gdb_core_transaction.go index 897b179b1d2..1faa73a6205 100644 --- a/database/gdb/gdb_core_transaction.go +++ b/database/gdb/gdb_core_transaction.go @@ -257,12 +257,14 @@ func WithTX(ctx context.Context, tx TX) context.Context { } // Inject transaction object and id into context. ctx = context.WithValue(ctx, transactionKeyForContext(group), tx) + ctx = context.WithValue(ctx, transactionIdForLoggerCtx, tx.GetCtx().Value(transactionIdForLoggerCtx)) return ctx } // WithoutTX removed transaction object from context and returns a new context. func WithoutTX(ctx context.Context, group string) context.Context { ctx = context.WithValue(ctx, transactionKeyForContext(group), nil) + ctx = context.WithValue(ctx, transactionIdForLoggerCtx, nil) return ctx } diff --git a/database/gdb/gdb_core_underlying.go b/database/gdb/gdb_core_underlying.go index 25c60a4baf7..61fd3d0eec8 100644 --- a/database/gdb/gdb_core_underlying.go +++ b/database/gdb/gdb_core_underlying.go @@ -180,14 +180,17 @@ func (c *Core) DoCommit(ctx context.Context, in DoCommitInput) (out DoCommitOutp formattedSql, in.TxOptions.Isolation.String(), in.TxOptions.ReadOnly, ) if sqlTx, err = in.Db.BeginTx(ctx, &in.TxOptions); err == nil { - out.Tx = &TXCore{ + tx := &TXCore{ db: c.db, tx: sqlTx, - ctx: context.WithValue(ctx, transactionIdForLoggerCtx, transactionIdGenerator.Add(1)), + ctx: ctx, master: in.Db, transactionId: guid.S(), cancelFunc: cancelFuncForTimeout, } + tx.ctx = context.WithValue(tx.ctx, transactionIdForLoggerCtx, transactionIdGenerator.Add(1)) + tx.ctx = WithTX(tx.ctx, tx) + out.Tx = tx ctx = out.Tx.GetCtx() } out.RawResult = sqlTx