I want to send an email whenever my Azure Function stops (maybe due to
a fatal error or manually from portal)
You can achieve this by writing multiple custom query as a signal condition & creating multiple alerts using the application insights logs/enabled diagnostic logs .
Function stops (maybe due to a fatal error)
Generally, fatal errors occurs during the run time or program execution based on this we have written the below custom query which will check whether the function execution is success or not if it fails it will compare the error message whether it is fatal or not .
requests| where success == false | project customDimensions,operation_Id,['id'],timestamp
|join kind =inner(exceptions| where severityLevel ==3 | where ['details'] contains "fatalerror" ) on operation_Id
using the above query you can create a custom alert by following the steps mentioned in this reference SO thread.
whenever my Azure Function stops(manually stop from the portal)
From the activity logs , you can pull the write operations that were happened on the particular function but the activity logs doesn't any column that can help us with the current status of the function & desired status post executing the operation. Based on my understanding we cannot create a alert when the function app got stopped using the logs or any metrics.