China's foreign trade rose by 3.7% year-on-year to $4 trillion (¥25.6 trillion) in the first eight months of 2024, spurred by a jump in the exports of mechanical and electrical products, official data showed.