Azure App insights for Java Springboot application

Prasun kumar Bheemireddy 21 Reputation points

Can anyone help me in implementing the Azure app insights for the Java Springboot application?

1/Which starter lib/pack need to be added in the pom.xml file
2/Where the instrumentation key/ConnectionString needs to be added
3/How to use the telemetry client in the code and configure with instrumentation key/ConnectionString, tracing/logging of the error, warn, and exceptions.
4/How to implement the correlation between the logs messages.
Please help with the code snippet if possible.

Azure App Configuration
Azure App Configuration
An Azure service that provides hosted, universal storage for Azure app configurations.
206 questions
{count} votes

Accepted answer
  1. svijay-MSFT 5,201 Reputation points Microsoft Employee

    @PrasunkumarBheemireddy-2372- Thanks for your questions I have answered them inline below.

    Which starter lib/pack need to be added in the pom.xml file?


    You could refer to this page for list of versions of applicationinsights-spring-boot-starter.

    Where the instrumentation key/ConnectionString needs to be added ?

    You will have to add the below line to the files which is present under the Resources folder.

    azure.application-insights.instrumentation-key=<YOUR KEY>  

    How to use the telemetry client in the code

    The below snippet is a sample code where. The REST API /GREETINGS returns "Hello World" and /USERS returns users from the backend.
    The snippet has been referenced from the Deep Application Monitoring post.
    The below snippet makes use of the Telemetry client to track success requests and errors (Exceptions)

    public class Controller {  
      UserRepo userRepo;  
      TelemetryClient telemetryClient;  
      public String greetings() {  
        // send event  
        telemetryClient.trackEvent("URI /greeting is triggered");  
        return "Hello World!";   
      public List<User> users() {  
        try {  
          List<User> users;  
          // measure DB query benchmark  
          long startTime = System.nanoTime();  
          users = userRepo.findAll();  
          long endTime = System.nanoTime();  
          MetricTelemetry benchmark = new MetricTelemetry();  
          benchmark.setName("DB query");  
          benchmark.setValue(endTime - startTime);  
          return users;  
        } catch (Exception e) {  
          // send exception information  
       telemetryClient.trackTrace("Exception: " + e.getMessage());  
          throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());   
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful