在 Application Insights 中查看请求正文

View Request Body in Application Insights

我正在使用 Application insights with API-Management 来监控我的 API。 Application Insights 是很棒的工具,但我看不到正文。

我想查看 Post 请求正文参数。有什么方法可以在应用洞察上添加正文数据吗??

I can't do code changes in existing api. any option without code change would help me

很遗憾,Application Insights 不支持它。

我也找到了feedback,你可以投票。

它现在支持 正如我向您展示的那样。

目前不支持。 APIM 不会向客户公开遥测初始化程序,而是提供添加到诊断实体的自定义选项,允许您控制采样、详细程度和记录 headers 的能力。 Body 还在争论中。用户是否希望看到从后端返回或发送到客户端的响应 body? Body 可以在不同的阶段进行修改。或者,您可以使用 Log-To-EventHub 并能够将其放置在管道的特定点。正在考虑的另一个想法是 Log-To-ApplicationInsights.

注意:向 Application Insights 添加更多数据会影响 APIM 性能。

最简单的方法(好的,我让它工作的唯一方法)是使用 AppInsights SDK 自己记录正文。

根据 GitHub,较新的 AppInsights SDK 在流关闭时具有初始化程序 运行 after 处理。

您必须配置 API 管理以将请求负载记录到 Application Insights。看这里:Enable Application Insights logging for your API

  1. 导航到 Azure 门户中的 Azure API 管理服务实例。
  2. Select API 左侧菜单。
  3. 点击您的API。
  4. 从顶部栏转到“设置”选项卡。
  5. 向下滚动到“诊断日志”部分。
  6. 选中“启用”框。
  7. Select 您在“目标”下拉列表中附加的记录器。
  8. 输入 100 作为采样 (%) 并勾选始终记录错误复选框。
  9. 在其他设置下,配置最多 8192 字节的要记录的有效负载。
  10. 点击保存。