在 Application Insights 上跟踪 HTTP 正文内容

Track HTTP body content on Application Insights

有什么方法可以将 HTTP 正文响应内容包含在 Application Insights HTTP 或依赖项跟踪模块中?了解请求的 HTTP 响应状态代码是什么很有用,但了解响应 message/data.

对我们来说真的很重要

我查看过创建自定义过滤器或初始化器,但似乎没有任何属性包含任何响应内容,我该如何包含它?

这实际上需要的不仅仅是检查 Response 对象的属性。您必须使用 Response Filter 才能在完成之前捕获主体。

下面的gist有两个文件。一个是 CaptureStream.cs 文件,它实现了 Stream 抽象 class 并且只传递信息。在此过程中,我们将数据附加到 StringBuilder 中。

另一个只是覆盖 Application_BeginRequest method and the Application_LogRequest 方法的 Global.asax.cs 的示例。

您可以在 ASP.NET Application Lifecycle 中选择您认为正确位置的任何方法。我选择这两个是因为这是我记得在其他项目中使用的前两个。

https://gist.github.com/debugthings/058f8c0634accfbdcce2c8c5b818d514

我刚刚在 Matthias Güntert answer from this other question

之后做了这个