azure - 如果未发送客户端,如何在 APIM 入站策略中获取/设置 Traceparent 标头?
问题描述
我们想要关联 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>
解决方案
可能发生的情况是它正在生成具有非法格式的 traceID,当这种情况发生时,它会生成一个新格式。
HEXDIGLC = DIGIT / "a" / "b" / "c" / "d" / "e" / "f" ; lowercase hex character
value = version "-" version-format
推荐阅读
- python - 如何在来自joblib的并行for循环期间附加列表
- kubernetes - K8S:将“kubeadm init”命令行参数转换为“--config”YAML
- stock - 我如何将 pinescript 用于 STOCKTRADE?
- google-sheets - UPS Tracking On Google Sheet 返回导入的内容为空
- python - 将简单代码从 python 转换为 ruby
- azure - 标记 Azure Databricks 的托管资源组
- angular - 具有多个模块的嵌套 Angular 组件 (Jhipster)
- mysql - 试图链接两个表,但在一个字段中获取所有信息
- python - 子python进程卡住了
- elasticsearch - 如何在elasticsearch中查找字段所属的索引?