Sahih Muslim 2680 a
Narration text is preserved in its supplied Arabic and English. Translated interfaces and reading guides do not add narration translations in other languages.
لاَ يَتَمَنَّيَنَّ أَحَدُكُمُ الْمَوْتَ لِضُرٍّ نَزَلَ بِهِ فَإِنْ كَانَ لاَ بُدَّ مُتَمَنِّيًا فَلْيَقُلِ اللَّهُمَّ أَحْيِنِي مَا كَانَتِ الْحَيَاةُ خَيْرًا لِي وَتَوَفَّنِي إِذَا كَانَتِ الْوَفَاةُ خَيْرًا لِي "
Anas (b. Malik) reported Allah's Messenger (ﷺ) as saying. None of you should make a request for death because of the trouble in which he is involved, but if there is no other help to it, then say:
O Allah, keep me alive as long as there is goodness in life for me and bring death to me when there is goodness in death for me.
Full reference and source
Sahih Muslim 2680 a In-book : Book 48, Hadith 10 USC-MSA web (English) : Book 35, Hadith 6480 (deprecated)
View source on Sunnah.com (opens in a new tab)