-2

Is it possible to provide a working JAVA example like the one in this post? View POST request body in Application Insights

Thanks for support

Mercury77
  • 45
  • 1
  • 10

1 Answers1

3

TelemetryModules track various data w.r.t HTTP request and send the same to AI servers as RequestTelemetry. In order to track any custom HTTP parameters one has to create a new TelemetryModule by Implementing WebTelemetryModule and TelemetryModule interface that comes part of app insight sdk.

Here is the sample implementation.

enter image description here

WebTelemetry modules are the ones that has access to the HttpRequest and HttpResponse objects in the Request lifecycle. Basically AI collects the request telemetry by registering a Servlet fitler and onBeginRequest gets called before the actual request is processed and onEndRequest gets called after the request is processed.

Now register the module in ApplicationInsights.xml file

enter image description here

<TelemetryModules>
        <Add type="com.ai.demo.CustomHttpTelemetryModule"/>
        <Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebRequestTrackingTelemetryModule"/>
        <Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebSessionTrackingTelemetryModule"/>
        <Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebUserTrackingTelemetryModule"/>
      </TelemetryModules>

Please note that, i have registered my TelemetryModule before all the default telemetries, because if you register your telemetry after WebRequestTelemetryModule then anything that you set in OnEndRequest will not be passed upon because WebRequestTelemetryModule makes trackRequest in its onEndRequest method. Any changes made post the trackRequest() call will not be reflected in AI portal.

TelemetryModules are executed in the order they are defined in the ApplicationInsights.xml file.

Integrating App Insights is pretty straight forward and the relevant documentation about the same can be found here.

https://learn.microsoft.com/en-us/azure/azure-monitor/app/java-get-started

Hope it helps.

Mohit Verma
  • 5,140
  • 2
  • 12
  • 27
  • 1
    Nice answer, but.. the link is dead and please use text instead of images. – Peter Bons Feb 25 '19 at 06:54
  • try to copy paste the url I have given in my answer, It works when we directly browse it. Sure will convert the images to text. – Mohit Verma Feb 25 '19 at 07:00
  • It seems to include a . at the very end of the url, which is not shown so copy / paste will work. – Peter Bons Feb 25 '19 at 07:01
  • my bad, forgot to remove ".". Now i have updated my answer with the correct link. – Mohit Verma Feb 25 '19 at 07:04
  • Thanks for explanation ,now I should be able to see those "CUSTOM_HEADER" sent with the request right? but using this query : requests | limit 1 | project customDimensions.HEADER-DATA does not produce any data ,maybe am I missing something ? – Mercury77 Feb 25 '19 at 14:47
  • my original request was to track POST requests parameters and not headers ,anyway it was well explained and it worked !! thank you – Mercury77 Feb 25 '19 at 21:07