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