Hi @Abhay Chandramouli Thanks for reaching out. you can use the Ocp-Apim-Trace header to trace request processing in APIM. Here’s how you can do it:
Enable Tracing: To trace request processing, you must enable the Allow tracing setting for the subscription used to debug your API.
Trace a Call: In the Azure portal, navigate to your API Management instance and select APIs. Select the operation you want to trace and go to the Test tab. Add an Ocp-Apim-Trace header with the value set to true.
Review Trace Information: After the call completes, go to the Trace tab in the HTTP response. Select any of the following links to jump to detailed trace info: Inbound, Backend, Outbound, On error. Each step also shows the elapsed time since the request is received by API Management.
Reference: https://learn.microsoft.com/en-us/azure/api-management/api-management-howto-api-inspector
or You could also enable diagnostic logging for your APIM services. Diagnostic Logs can be archived to a storage account, streamed to an Event Hub resource, or be sent to Azure Monitor Log Analytics logs which could be further queried as per the scenario and requirement.
These logs provide rich information about operations and errors that are important for auditing as well as troubleshooting purposes. The best part about the diagnostic logs is that they provide you with granular level per-request logs for each of your API requests and assist you with further troubleshooting.
you would be offered with the below 2 modes of resource log collection:
- Azure diagnostics - Data is written to the AzureDiagnostics table, which collates diagnostic information from multiple resources of different resource types.
- Resource specific - Data is written to individual table for each category of the resource. For APIM, the logs would be ported to ApiManagementGatewayLogs table
Below are the sample diagnostic logs generated on the Log Analytics Workspace. These logs would provide granular level details for your API requests such as the timestamp, request status, api/operation id, time taken values (total time, backend time, client time) etc..
- totalTime - Total time for the request measured from the first byte received to last byte sent to the client. This includes backend roundrip and client ability to read.
- backendTime - Number of milliseconds spent on overall backend IO (connecting, sending, and receiving bytes). If this time is high, it means the backend is slow and the performance investigation needs to be focused there.
- clientTime - Number of milliseconds spent on overall client I/O (connecting, sending, and receiving bytes). If this time is high, the client bandwidth or processing might not allow to read response fast.
Another option is to integrate APIM service with Application Insights for generating diagnostic log data.
Integration of APIM with Application Insights - https://docs.microsoft.com/en-us/azure/api-management/api-management-howto-app-insights
let me know incase of further queries, 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 looking for help on similar topics.