如何使用Azure CLI脚本将Azure应用程序洞察正确连接到App Service Spring应用程序? [英] How to properly connect Azure Application Insights to the App Service Spring Application with Azure CLI scripts?

查看:0
本文介绍了如何使用Azure CLI脚本将Azure应用程序洞察正确连接到App Service Spring应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过Azure应用程序服务和Azure CLI脚本托管了我的Spring Boot应用程序。此外,我还使用Azure CLI脚本在同一订阅上部署了Azure应用程序洞察。我的下一步是仅使用az命令和补充文件将App Insights与App Service连接。

我已经阅读了this文档,了解如何以无代码方式连接App Insights。但看起来我仍然缺少很多指标,如请求、依赖项、异常等(尽管我在类路径中有微指标)。应用程序洞察|搜索只有痕迹,所以我尝试从Azure门户网站连接它,它起作用了。这个集成重新启动了我的应用程序,并产生了一些我不知道的魔力:

以下是我从Azure门户连接App Insights之前和之后的图像:

查看App Service的配置时,我发现了文档中没有描述的几个新值:

{
  "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"
}

因此我的问题是,我如何使用Azure CLI脚本模拟此按钮,以便它对我的日志和指标产生完全相同的影响?&q;

推荐答案

在将JAR文件部署到App Services之前,请确保您在类路径中具有与AI SDK的最新依赖关系。提供我的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'

现在,在编译应用程序后,可以使用此Azure CLI脚本将Application Insights连接到App Service:

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

以下是我的VM环境变量:APP_SERVICE_JAVA_OPTS="-javaagent:/home/site/wwwroot/applicationinsights-agent.jar -Dserver.port=80"

如您所见,我有一个指向Applationinsights-agent.jar的路径,这是我在部署过程中使用配置压缩部署复制的JAR:

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}

我的ApplicationInsights.json看起来是这样:

{
  "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
      }
    }
  }
}

这篇关于如何使用Azure CLI脚本将Azure应用程序洞察正确连接到App Service Spring应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆