Ikrima bin Khalid reported,

Abu Tufayl narrated that he said, "I visited Abu Sariha Huzaifa bin Usayd al-Ghifari, and he said, 'I heard the Messenger of Allah ﷺ with these two ears of mine saying, "The drop of fluid settles in the womb for forty nights, then the angel takes form over it."'"Zuhayr said, "I think he said, 'the one who fashions it.'""The angel says, 'My Lord, male or female?' So Allah makes it male or female. Then he says, 'My Lord, sound in form or not sound in form?' So Allah makes it sound or not sound. Then he says, 'My Lord, what is its provision? What is its lifespan? What is its disposition?' Then Allah makes it wretched or happy."

Azami 1004

Sahih

عن عكرمة بن خالد

أن أبا الطفيل حدثه قال: دخلت على أبي سريحة حذيفة بن أسيد الغفاري فقال: سمعت رسول الله ﷺ بأذني هاتين يقول: إن النطفة تقع في الرحم أربعين ليلة، ثم يتصور عليها الملك. قال زهير: حسبته قال الذي يخلقها: فيقول: يا رب أذكر أو أنثى؟ فجعله الله ذكرا أو أنثى، ثم يقول: يا رب أسوي أو غير سوي؟ فيجعله الله سويا أو غير سوي. ثم يقول: يا رب ما رزقه؟ ما أجله؟ ما خلقه؟ ثم يجعله الله شقيا أو سعيدا.

الأعظمي 1004صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Faith
Chapter
Belief in the divine decree and predestination
Section
How the human is created in his mother's womb and the recording of his provision, lifespan, deeds, misery, and happiness
Numbering
Jami al-Kamil 1004 (2nd edition)
Azami 1004