@Deshmukh, Vijit Thank you for reaching out to Microsoft Q&A. Based on your statement, you have integrated APIM with Application Insights and wanted to log detailed API response message for errors like 500 and 504.
Have you looked at docs: Enable Application Insights logging for your API? You can use "Always log errors" setting to log all failures to Application Insights, regardless of the Sampling setting.
For more detailed error info, you can change Verbosity to Verbose
and add Headers to log
for both Backend Response and Frontend Response and this would help in reviewing the errors. Refer to docs for more info about this setting.
Second part on querying Application Insights, you can navigate to Application Insights -> Transaction Search and select timeframe and event type -> Exception to search the results. Then double click the search result to view End to End Transaction details. Refer to the docs: Viewing Azure Application Insights Data for each steps.
I hope this answers your question and feel free to add if you have any questions. I would be happy to assist you.
Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community.