Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Track HTTP body content on Application Insights

Is there any way to include the HTTP Body response content in Application Insights HTTP or dependency tracking modules? Its useful knowing what the HTTP response status code of a request is, but its really important us to know what the response message/data.

Ive looked at creating a custom Filter or Initializer but no properties seem to have any response content, how can I include it?

like image 685
gorillapower Avatar asked Sep 07 '16 12:09

gorillapower


1 Answers

This actually requires a bit more than inspecting the properties of your Response object. You will have to use a Response Filter in order to capture the body before it's done.

The gist below has two files. One is the CaptureStream.cs file that implements a Stream abastract class and just passes along the information. Along the way we append data in a StringBuilder.

In the other is just an example of a Global.asax.cs that overrides the Application_BeginRequest method and the Application_LogRequest method.

You can choose any method in the ASP.NET Application Lifecycle that you think is the right location. I chose these two because it was the first two I remember using in other projects.

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

like image 139
James Davis - MSFT Avatar answered Sep 17 '22 11:09

James Davis - MSFT