skip to Main Content

I wanted to integrate application insights into my spring boot application**(v3.x.x)** and for that I have used below dependency in my build.gradle.

implementation 'com.microsoft.azure:applicationinsights-spring-boot-starter:2.6.4'

In my controller, I have injected TelemetryClient bean like:

@RestController
@RequestMapping("/")
public class UserController {
    @Autowired
    TelemetryClient telemetryClient;

    @GetMapping("/greetings")
    public String greetings() {
        // send event
        telemetryClient.trackEvent("URI /greeting is triggered");

        return "Hello World!";
    }
}

And, To connect to my azure app insights I used :

APPLICATIONINSIGHTS_CONNECTION_STRING=somevalue

as Environment variable while running application in IntellijIdea.

Now, Application runs and complains about:

***************************
APPLICATION FAILED TO START
***************************

Description:

Field telemetryClient in com.example.demo.app.insights.UserController required a bean of type 'com.microsoft.applicationinsights.TelemetryClient' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'com.microsoft.applicationinsights.TelemetryClient' in your configuration.

But, as soon as I downgrade my spring boot version from 3.x.x to 2.7.11, it works fine with the same piece of code and starts the application.

Has anyone else also has experienced similar issue of appinsights with spring boot on 3.x.x ? or Any idea of its fix in latest spring boot version ?

2

Answers


  1. Chosen as BEST ANSWER

    This issue has been resolved in https://github.com/microsoft/ApplicationInsights-Java/issues/3016

    Below dependency is compatible with spring boot 3.x:

    api('com.microsoft.azure:applicationinsights-core:3.4.11');
    // api 'com.microsoft.azure:applicationinsights-spring-boot-starter:2.6.4' // not compatible with spring 3.x
    

    After that TelemetryClient Bean can be injected like:

    @RestController
    @RequestMapping("/")
    public class UserController {
    
        private final TelemetryClient telemetryClient = new TelemetryClient();
    
        @GetMapping("/greetings")
        public String greetings() {
            // send event
            telemetryClient.trackEvent("URI /greeting is triggered");
    
            return "Hello World!";
        }
    }
    

  2. I have tried with the same dependency with spring boot 3.x.x version, and I got the same error:

    enter image description here

    Result:

    I was getting the same error as you mentioned above:
    enter image description here

    • After researching from my end, I found that there is no compatible version of Azure application insights with spring boot 3.x.x yet. The latest compatible version is 2.7.x.
    • The latest version of Azure Application insights is 3.0.0-beta.1 and it is compatible only with spring boot 2.x.x version.
    • Hence, it is better to use 2.x.x versions rather than using 3.x.x.

    References:

    Refer to github issue regarding the release of Application Insights SpringBoot Starter library.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search