Api Management | Logs

Abhay Chandramouli 1,061 Reputation points
2023-09-27T11:44:15.74+00:00

Hi,

I want to check how much time the inbound section, outbound section, backend section and on error sections has taken separately..

How to get this via app insights or any other way

Please advice

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
0 comments No comments
{count} votes

Answer accepted by question author
  1. JananiRamesh-MSFT 29,436 Reputation points Moderator
    2023-09-27T13:29:19.6633333+00:00

    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.

    Reference: https://learn.microsoft.com/en-us/azure/api-management/api-management-howto-use-azure-monitor#resource-logs

    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

    Reference: https://learn.microsoft.com/en-us/azure/azure-monitor/essentials/resource-logs#send-to-log-analytics-workspace

    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..

    User's image

    1. 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.
    2. 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.
    3. 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

    reference: https://techcommunity.microsoft.com/t5/azure-paas-blog/troubleshooting-4xx-and-5xx-errors-with-azure-apim-services/ba-p/2115752

    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.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.