1

I have my Spring Boot application hosted via Azure App Service with Azure CLI scripts. Also I deployed Azure Application Insights on the same subscription with Azure CLI scripts. My next step is to connect App Insights with App Service using only az commands and supplementary files.

I have gone through this documentation on how to connect App Insights codeless way. But it appeared I was still lacking a lot of metrics like requests, dependencies, exceptions and etc (although I have micrometrics in the classpath). Application Insights | Search only had traces, so I tried to connect it from Azure Portal and it worked. This integration restarted my application and did some magic I don't know about: enter image description here

Here is an image of before I connected App Insights from Azure Portal and after: app insights stats

Looking into the configuration of the App Service I saw several new values which were NOT described in the documentation:

{
  "XDT_MicrosoftApplicationInsights_PreemptSdk": "disabled",
  "XDT_MicrosoftApplicationInsights_Mode": "recommended",
  "XDT_MicrosoftApplicationInsights_BaseExtensions": "disabled",
  "SnapshotDebugger_EXTENSION_VERSION": "disabled",
  "InstrumentationEngine_EXTENSION_VERSION": "disabled",
  "DiagnosticServices_EXTENSION_VERSION": "~3",
  "APPINSIGHTS_PROFILERFEATURE_VERSION": "1.0.0",
  "APPINSIGHTS_INSTRUMENTATIONKEY": "key",
  "APPINSIGHTS_SNAPSHOTFEATURE_VERSION": "1.0.0",
  "ApplicationInsightsAgent_EXTENSION_VERSION": "~2"
}

So my question is "How do I mimic this button with my Azure CLI scripts so it will have absolutely the same impact on my logs and metrics?"

Praytic
  • 1,771
  • 4
  • 21
  • 41

1 Answers1

1

Before deploying your jar file to the App Services make sure you have latest dependencies with AI SDK in the classpath. Providing my set of the dependencies imported by Gradle:

//    Application Insights
    implementation "com.microsoft.azure:applicationinsights-spring-boot-starter:$appInsightsVersion"
    implementation "com.microsoft.azure:applicationinsights-logging-logback:$appInsightsVersion"
    implementation 'com.microsoft.azure:azure-spring-boot-metrics-starter'

Now after you compiled your application it's time to connect Application Insights to App Service using this Azure CLI script:

az webapp config appsettings set \
  -n ${APP_NAME} \
  -g ${GROUP_NAME} \
  --settings \
APPINSIGHTS_INSTRUMENTATIONKEY=${APPINSIGHTS_INSTRUMENTATIONKEY} \
JAVA_OPTS="${APP_SERVICE_JAVA_OPTS}"

Here is my environment variable for VM: APP_SERVICE_JAVA_OPTS="-javaagent:/home/site/wwwroot/applicationinsights-agent.jar -Dserver.port=80"

As you can see I have a path to applicationinsights-agent.jar which is the jar I copy myself during the deployment using config-zip deployment:

cp ./build/libs/app-0.0.1-SNAPSHOT.jar ./deploymentrepo/app.jar
cp ./build/resources/main/applicationinsights-agent*.jar ./deploymentrepo/applicationinsights-agent.jar
cp ./build/resources/main/ApplicationInsights.json ./deploymentrepo/ApplicationInsights.json
cd ./deploymentrepo
zip target.zip -r ./*
az webapp deployment source config-zip \
  --src target.zip \
  -n ${ANALYTICS_APP_NAME} \
  -g ${ANALYTICS_GROUP_NAME}

My ApplicationInsights.json looks like that:

{
  "instrumentationSettings": {
    "preview": {
      "roleName": "ApplicationName",
      "heartbeat": {
        "intervalSeconds": 60
      },
      "instrumentation": {
        "logging": {
          "threshold": "INFO"
        },
        "micrometer": {
          "enabled": true
        }
      },
      "selfDiagnostics": {
        "destination": "file",
        "directory": "/var/log/applicationinsights",
        "level": "INFO",
        "maxSizeMB": 10
      }
    }
  }
}
Praytic
  • 1,771
  • 4
  • 21
  • 41