skip to Main Content

I new to Azure App Insights. I am trying to configure it in my Spring Boot + Kotlin application. So far, after reading the guides. I have added the dependency:

<!-- https://mvnrepository.com/artifact/com.microsoft.azure/applicationinsights-runtime-attach -->
<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>applicationinsights-runtime-attach</artifactId>
    <version>3.4.9</version>
</dependency>

and in my application.yaml file, I added:

applicationinsights:
  runtime-attach:
    configuration:
      classpath:
        file: my_app_insights.json

My my_app_insights.json (resides in src/main/resources) contains:

{
  "connectionString":"A_VERY_LONG_CONNECTION_STRING",
  "sampling":{
    "requestsPerSecond":100
  },
  "instrumentation":{
    "logging":{
      "level":"INFO"
    },
    "jdbc":{
      "masking":{
        "enabled":true
      }
    }
  }
}

And in my Spring Boot main class I have done this:

fun main(args: Array<String>) {

    // Attach Azure Application Insights here.
    ApplicationInsights.attach()

    runApplication<MyDownloadApplication>(*args)
}

But when I start my spring boot application the usual way using mvn spring-boot:run...

I get the following error:

2023-02-21 18:41:11.152+05:30 ERROR c.m.applicationinsights.agent - 
*************************
Application Insights Java Agent 3.4.9 startup failed (PID 18436)
*************************

Description:
No connection string provided

Action:
Please provide connection string.

18:41:11.582 [Thread-0] DEBUG org.springframework.boot.devtools.restart.classloader.RestartClassLoader - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@306e2a0a
Feb 21, 2023 6:41:11 PM com.microsoft.applicationinsights.attach.ApplicationInsights attach
WARNING: Application Insights is already attached. It is not attached a second time.

Can you please tell me what am I doing wrong here? Do I need to add any other dependencies? Or is it the file name?

Any pointers would be helpful.

2

Answers


  1. applicationinsights.runtime-attach.configuration.classpath.file property can’t be defined in application.properties or application.yaml. Instead, it has to be defined with -D, for example -Dapplicationinsights.runtime-attach.configuration.classpath.file=applicationinsights-dev.json.

    Another option is to no use -Dapplicationinsights.runtime-attach.configuration.classpath.file. In this case, Application Insights will search an applicationinsights.json file in the classpath (src/main/resources, src/test/resources).

    Other configuration options exist for the Application Insights json file and are given here.

    Login or Signup to reply.
  2. You have to add -Dspring-boot.run.jvmArguments with spring-boot:run. For example, if you have an applicationinsights-dev.json file in your classpath (src/main/resources, src/test/resources), you have to execute

    mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dapplicationinsights.runtime-attach.configuration.classpath.file=applicationinsights-dev.json"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search