我们想要关联 Azure APIM 和 Application Insight 中的请求。对于 API,我们有一个在入站和出站部分使用发送请求的策略。我们正在使用W3C 分布式跟踪 Azure,规范
现在,如果客户端不发送 traceparent 标头,则入站中的发送请求在应用程序洞察力中没有关联。
如果我们尝试在入站策略中设置 traceparent 标头,它将在策略的后端部分被覆盖。看起来 APIM 检查传入的请求,如果没有设置 traceparent,它将生成它。但是我们不能在策略中的传入请求中添加标头(只读)。
示例政策
<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>