we want to correlate requests in Azure APIM and Application Insight. For the API we have a policy that uses send-request in inbound and outbound section. We are using W3C distributed tracing Azure , specification
Now if the client dose not send the traceparent header the send-request in the inbound is not being correlated in application insight.
if we try to set the traceparent header in the inbound policy it will be overwritten in the backend part of the policy. It looks like APIM checks the incoming request and if no traceparent is set it will generate it. But we cannot add headers to the incoming request in the policy (read only).
Sample policy
<policies>
<inbound>
<base />
<send-request mode="new" response-variable-name="inboundresponse" timeout="10" ignore-error="true">
<set-url>https://someUrl.com</set-url>
<set-method>GET</set-method>
<set-header name="traceparent" exists-action="skip">
<value>00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01</value>
</set-header>
<set-body></set-body>
</send-request>
<!-- for test set fixed value, but this value is overwritten by Azure APIM in backend
and all 3 requests are not coorrelated -->
<set-header name="traceparent" exists-action="skip">
<value>00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01</value>
</set-header>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
<!-- traceparent value we get here is not the same that we set -->
<send-request mode="new" response-variable-name="outboundresponse" timeout="10" ignore-error="true">
<set-url>https://someUrl.com</set-url>
<set-method>GET</set-method>
<set-header name="traceparent" exists-action="skip">
<value>00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01</value>
</set-header>
<set-body></set-body>
</send-request>
</outbound>
<on-error>
<base />
</on-error>
</policies>