6

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?

gorillapower
  • 450
  • 6
  • 15
  • Are you asking for the Dependency Tracking Module to capture the response from your service call, or are you asking to capture the response of your server request from the application being instrumented by application insights? – James Davis - MSFT Sep 07 '16 at 15:37
  • Yes I want to capture the response from the service call _within_ my application...but would it be useful to capture the 'server request response' too. Perhaps there is a potential for the response to be too large, hence why it isnt being captured in the first place? – gorillapower Sep 08 '16 at 15:37

2 Answers2

3

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

James Davis - MSFT
  • 1,736
  • 10
  • 12
  • You should turn that into a NuGet package so that people can bolt it on next to Insights. Thanks for sharing. – Piotr Kula Jun 02 '17 at 07:19
  • I know the question is old but do you know if there is a way to filter the outbound requests in a similar way? I want to add the content body to the request telemetry but only on some external API call. I'm on .net framework 4.7.2. – user2509192 May 07 '21 at 15:23
1

I just did this following Matthias Güntert answer from this other question View POST request body in Application Insights

JoanComasFdz
  • 2,911
  • 5
  • 34
  • 50