Sahih al-Bukhari 5671
Narration text is preserved in its supplied Arabic and English. Translated interfaces and reading guides do not add narration translations in other languages.
لاَ يَتَمَنَّيَنَّ أَحَدُكُمُ الْمَوْتَ مِنْ ضُرٍّ أَصَابَهُ، فَإِنْ كَانَ لاَ بُدَّ فَاعِلاً فَلْيَقُلِ اللَّهُمَّ أَحْيِنِي مَا كَانَتِ الْحَيَاةُ خَيْرًا لِي، وَتَوَفَّنِي إِذَا كَانَتِ الْوَفَاةُ خَيْرًا لِي "
Narrated Anas bin Malik:
The Prophet (ﷺ) said, "None of you should wish for death because of a calamity befalling him; but if he has to wish for death, he should say: "O Allah! Keep me alive as long as life is better for me, and let me die if death is better for me.' "
Full reference and source
Sahih al-Bukhari 5671 In-book : Book 75, Hadith 32 USC-MSA web (English) : Vol. 7, Book 70, Hadith 575 (deprecated)
View source on Sunnah.com (opens in a new tab)