Assuming that we encounter failed requests or unexpected response while invoking Azure Logic App API through Azure API Management service, we need to narrow down the issue based on the request monitor log in the APIM and Azure Logic App at the same time. However, as APIM service and Logic App service are two completely different azure services, they have different logging mechanisms in these two systems. Hence, there is no built-in property or field in the log which links both two systems.
This blog’s purpose is to guide users to manually add one property named x-correlation-id in both of APIM and Azure Logic App and do some extra steps to link these two systems using the generated x-correlation-id for troubleshooting specific request.
Before we start, we could make sure that we have exiting in the APIM service and Azure Logic App.
We need settings on both APIM and logic App sides.
1.On APIM side:
Navigate to inbound policy on API or Operation layer, do the following changes:
Snippet of policy definition:
<inbound>
<!--Use consumer correlation id or generate new one-->
<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="Global APIM Policy" severity="information">
<message>@(String.Format("{0} | {1}", context.Api.Name, context.Variables[“correlation-id”]))</message>
<metadata name="correlation-id" value="@((string)context.Variables["correlation-id"])" />
</trace>
<base />
</inbound>
You could refer to the statement of above <message> and <metadata> from this link: https://docs.microsoft.com/en-us/azure/api-management/api-management-advanced-policies#elements-14
3. Test and monitor:
Now, we could send request to Logic App through APIM to test our request tracking.
In the APIM, send a call to Logic App.
We could observe the generated x-correlation-id header in the trace log.
The value of generated correlation-id in the <message> could be found in the APIM Portal---- Logs----- ApiManagementGatewayLogs table ----- TraceRecords property.
Some Tips:
Now, we could narrow down further regarding specific request between separate two services(APIM and Logic App) which have different log systems.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.