Application Insights Headers to Log values

Elaiza Rose Marcelo 1 Reputation point
2022-01-28T11:22:23.027+00:00

Hi everyone! I am quiet new to Azure APIM and App Insights. I would like to know where should I get the values of the Headers to log for the ff. fields:

  • Frontend Request
  • Frontend Response
  • Backend Request
  • Backend Response

Basically, I need to add the uuid and request-uuid but I don't know what is the reference for this or if this is a valid value.

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
2,778 questions
Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,722 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 67,906 Reputation points
    2022-02-02T04:34:07.167+00:00

    @Elaiza Rose Marcelo Thanks for reaching out. I believe you want to do the end to end tracing for each request that is coming to your APIM so you can track the request flow from the front end --> APIM --> backend service configured in APIM --> Response from your backend service --> return response from APIM. Please correct me if my understanding is correct.

    From the APIM perspective, you can set correlationid header on your global policy to trace the request. You can refer to this document on how you can set it.
    To enable the Application Insights logging for your API you can refer to this document.

    Global Inbound Policy:

    <!--Use front end correlation id or generate new one if there is no correlation ID-->  
    <set-variable name="correlation-id" value="@(context.Request.Headers.GetValueOrDefault("x-correlation-id", Guid.NewGuid().ToString()))"/>  
      
    <!--Set header for end-to-end correlation-->  
    <set-header name="x-correlation-id" exists-action="override">  
       <value>@((string)context.Variables["correlation-id"])</value>  
    </set-header>  
      
    <!--Trace the correlation id-->  
    <trace source="My Global APIM Policy" severity="information">  
       <message>@(String.Format("{0} | {1}", context.Api.Name, context.Operation.Name))</message>  
       <metadata name="correlation-id" value="@((string)context.Variables["correlation-id"])"/>  
    </trace>  
    

    With this simple outbound policy, we return the correlation id, so it can be used for troubleshooting.

    Global Outbound Policy:

    <!--Set header for end-to-end correlation-->  
    <set-header name="x-correlation-id" exists-action="override">  
       <value>@((string)context.Variables["correlation-id"])</value>  
    </set-header>  
    

    The above policy is just for reference and you can add more value/parameter/trace as per your requirement.
    Feel free to get back to me if you have any queries or concerns.

    0 comments No comments