1
votes

We have a Java web application that uses Play Framwork. How can I add web request logging using Application Insights? Documentation is available for other project types https://docs.microsoft.com/en-us/azure/azure-monitor/app/java-get-started#4-add-an-http-filter

1
facing the same question...Sharon Ben Asher

1 Answers

0
votes

Assuming you are using playframework 2.7, on the Java side, there are JavaHttpFilters. https://www.playframework.com/documentation/2.7.x/JavaHttpFilters

Unfortunately, these do not implement javax.servlet.Filter which is what the documentation you linked to uses. The documentation says you should register the filter WebRequestTrackingFilter. Basically it fills out a RequestTelemetry using an HttpServerHandler then sends it to ApplicationInsights using a TelemetryClient.

In your play.mvc.Filter, you will do the same thing. Create a TelemetryClient (you probably want to use DI to inject this into your Filter). In your Filter's apply method, create a RequestTelemetry, then send it using TelemetryClient#trackRequest.