skip to Main Content

By default, Azure’s Application Insights only captures events at the INFO level and above. I want to change the default level to INFO in a Spring Boot app. I tried to achieve this by adding the following configuration section in application.yml

azure: 
  application-insights:
    enabled: true
    connection-string: 'my-secret-connection-string'
    logger:
      level: DEBUG

logging:
  level:
    root: INFO
    com.myapp: DEBUG
    com.microsoft.azure.telemetry: DEBUG

But it doesn’t seem to have worked. How can I change the default logging level for Application Insights?

I’m using Spring Boot v3.2.2 with applicationinsights-web v3.4.19

2

Answers


  1. Chosen as BEST ANSWER

    I eventually figured out that the Spring configuration has no impact on the Application Insights log level. The correct place to configure this is in an applicationinsights.json file that looks like this

    {
      "role": {
        "name": "MyApp"
      },
      "sampling": {
        "percentage": 100
      },
      "instrumentation": {
        "logging": {
          "level": "DEBUG"
        }
      }
    }
    

  2. How can I change the default logging level for Application Insights?

    The configuration you provided seems correct, but it might not be taking effect.

    • It is not recognizing this configuration properly. Instead, you should configure the logging level using Spring Boot’s logging configuration properties.

    application.yml file:

    azure:
      application-insights:
        instrumentation-key: YOUR_INSTRUMENTATION_KEY
    
    logging:
      level:
        com.microsoft.azure.telemetry: INFO
    

    Replace INFO with the desired logging level (e.g., INFO, DEBUG, WARN, ERROR).

    & also check whether you’re specifying the correct logger name for Application Insights. The logger name for Application Insights might vary based on the Azure SDK version or logging framework being used.

    enter image description here

    Dependencies used in pom.xml:

    <dependency>  
     <groupId>com.microsoft.azure</groupId>  
     <artifactId>applicationinsights-runtime-attach</artifactId>  
     <version>3.4.18</version>  
    </dependency>  
    <dependency>  
     <groupId>com.microsoft.azure</groupId>  
     <artifactId>applicationinsights-core</artifactId>  
     <version>3.4.18</version>  
    </dependency>
    

    App insights:

    enter image description here

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