springspring-bootazureazure-application-insightsazure-aks

How to configure Azure Application Insight for a Java Spring Boot in a Pod in Azure AKS


I have a SpringBoot app and this is running in a POD in AKS. I configured an Application Insights agent. For me all looks good. But i can not see in Application Insights the data that i would expect. eg the HeapSpace. Maybe I am just too stupid to find the info. Quesiton: I my setup so ok?

SpringBoot 3.3.3

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

I configured the following Enviromant Variables for my Pod APPLICATIONINSIGHTS_CONNECTION_STRING APPLICATIONINSIGHTS_AUTHENTICATION_STRING

When the Pod starts up I see the following output for the Agent:

  WARNING: A Java agent has been loaded dynamically (/tmp/otel-agent3340747174827410017/agent.jar)                                                                                                                                                                                                                      │
  │ WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning                                                                                                                                                                                                      │
  │ WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information                                                                                                                                                                                                     │
  │ WARNING: Dynamic loading of agents will be disallowed by default in a future release                                                                                                                                                                                                                                  │
  │ OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended                                                                                                                                                                                     │
  │ 2024-09-19 09:18:27.414Z INFO  c.m.a.a.i.c.ConfigurationBuilder - Some telemetry may be sampled out because a default sampling configuration was added in version 3.4.0 to reduce the default billing cost. You can set the sampling configuration explicitly: https://learn.microsoft.com/azure/azure-monitor/app/ja │
  │ 2024-09-19 09:18:29.791Z INFO  c.m.applicationinsights.agent - Application Insights Java Agent 3.5.4 started successfully (PID 1, JVM running for 3.66 s)                                                                                                                                                             │
  │ 2024-09-19 09:18:29.797Z INFO  c.m.applicationinsights.agent - Java version: 21.0.4, vendor: Eclipse Adoptium, home: /opt/java/openjdk                                                                                                                                                                                │
  │                                                                                                                                                                                                                                                                                                                       │
  │   .   ____          _            __ _ _                                                                                                                                                                                                                                                                               │
  │  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \                                                                                                                                                                                                                                                                              │
  │ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \                                                                                                                                                                                                                                                                             │
  │  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )                                                                                                                                                                                                                                                                            │
  │   '  |____| .__|_| |_|_| |_\__, | / / / /                                                                                                                                                                                                                                                                             │
  │  =========|_|==============|___/=/_/_/_/                                                                                                                                                                                                                                                                              │
  │                                                                                                                                                                                                                                                                                                                       │
  │  :: Spring Boot ::                (v3.3.3)

                                                                                                                                                                                                                                                                                                                 

Solution

  • To configure Application Insights for your Spring Boot app deployed inside AKS

    Create an Application Insights

    az monitor app-insights component create --app springboot-appinsights --location eastus --resource-group arkorg --kind web --application-type java
    

    enter image description here

    Retrieve the Connection String

    az monitor app-insights component show --app springboot-appinsights --resource-group arkorg --query connectionString --output tsv
    

    enter image description here

    Update your pom.xml accordingly. Push the Spring Boot Docker Image to your Azure Container Registry and use that same inside your aks deployment and service yaml

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: springboot-app
      labels:
        app: springboot-app
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: springboot-app
      template:
        metadata:
          labels:
            app: springboot-app
        spec:
          containers:
          - name: springboot-app
            image: arkoacr.azurecr.io/springboot-app:latest
            ports:
            - containerPort: 8080
            env:
            - name: APPLICATIONINSIGHTS_CONNECTION_STRING
              value: "<Your-Application-Insights-Connection-String>"
            - name: APPLICATIONINSIGHTS_JVM_METRICS
              value: "true"
          imagePullSecrets:
          - name: acr-secret
    
    

    service

    apiVersion: v1
    kind: Service
    metadata:
      name: springboot-service
    spec:
      type: LoadBalancer
      selector:
        app: springboot-app
      ports:
        - protocol: TCP
          port: 80
          targetPort: 8080
    
    

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    Now go to your application insights and under live metrics you can monitor your spring boot app deployed inside your aks

    enter image description here

    enter image description here

    Azure Application Insights is now configured for your Spring Boot application running in the AKS pod. From Live Metrics Stream, you can see the request rate is being tracked, and you can see successful (200 OK) and failed (404) HTTP requests in the telemetry. The Dependency Call Rate and Dependency Call Duration are also being monitored, meaning that Application Insights is capturing outgoing calls from your application.

    You can even verify the same inside the aks cluster as well-

    enter image description here