gpt4 book ai didi

Java - Azure Application Insights 动态跟踪不适用于 docker 镜像

转载 作者:行者123 更新时间:2023-12-02 06:37:26 26 4
gpt4 key购买 nike

Azure Functions 具有 App Insights 的 Java 动态跟踪功能。它收集针对多个库的指标。完整列表 here .

根据this ,对于 Linux,添加配置 ApplicationInsightsAgent_EXTENSION_VERSION=~3 应该可以使其工作。如果将 azure 函数部署为代码运行时,它会按预期工作。

但是当azure功能部署在docker上时,它不起作用!

最佳答案

自 2022 年 2 月起,动态跟踪功能(针对 Java)会自动针对代码运行时发挥作用。

为了使其与 docker 镜像一起工作,这就是我所做的(如果它也开始针对 docker 镜像自动运行,可能只是时间问题)。

<小时/>

要使其同时工作:

  1. mvn clean 包
  2. 更新您的 Dockerfile:
ARG JAVA_VERSION=8
# This image additionally contains function core tools – useful when using custom extensions
#FROM mcr.microsoft.com/azure-functions/java:3.0-java$JAVA_VERSION-core-tools AS installer-env
FROM mcr.microsoft.com/azure-functions/java:3.0-java$JAVA_VERSION-build AS installer-env

COPY . /src/java-function-app

RUN cd /src/java-function-app && \
mkdir -p /home/site/wwwroot && \
cd ./target/azure-functions/ && \
cd $(ls -d */|head -n 1) && \
cp -a . /home/site/wwwroot && \
cd /home/site/wwwroot && \
curl -SL --output applicationinsights-agent-3.2.6.jar https://github.com/microsoft/ApplicationInsights-Java/releases/download/3.2.6/applicationinsights-agent-3.2.6.jar


# This image is ssh enabled
FROM mcr.microsoft.com/azure-functions/java:3.0-java$JAVA_VERSION-appservice
# This image isn't ssh enabled
#FROM mcr.microsoft.com/azure-functions/java:3.0-java$JAVA_VERSION

ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true

COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]

上面假设在创建 docker 镜像之前已经完成了mvn clean package

  • 最后,将代理路径添加为 JAVA_OPTS。这是我的 pom.xml 的样子:

  • <plugin>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-functions-maven-plugin</artifactId>
    <version>${azure.functions.maven.plugin.version}</version>
    <configuration>
    <appName>${functionAppName}</appName>
    <resourceGroup>xxxxx</resourceGroup>
    <appServicePlanName>dockertemp2-appservice</appServicePlanName>
    <region>centralus</region>
    <pricingTier>P1V2</pricingTier>
    <runtime>
    <os>docker</os>
    <image>xxxxx.azurecr.io/dockertemp:v0.0.2</image>
    <serverId>SERVER_ID</serverId>
    <registryUrl>xxxxx.azurecr.io</registryUrl>
    </runtime>
    <appSettings>
    <property>
    <name>FUNCTIONS_EXTENSION_VERSION</name>
    <value>~3</value>
    </property>
    <property>
    <name>JAVA_OPTS</name>
    <value>-javaagent:/home/site/wwwroot/applicationinsights-agent-3.2.6.jar</value>
    </property>
    </appSettings>
    </configuration>
    <executions>
    <execution>
    <id>package-functions</id>
    <goals>
    <goal>package</goal>
    </goals>
    </execution>
    </executions>
    </plugin>

    最后,推送docker镜像并部署azure功能。

    mvn clean install package -DskipTests
    docker build --tag xxxxx.azurecr.io/dockertemp:v0.0.2 .
    docker push xxxxx.azurecr.io/dockertemp:v0.0.2
    mvn azure-functions:deploy

    最后,能够看到动态跟踪的实际效果:

    enter image description here

    关于Java - Azure Application Insights 动态跟踪不适用于 docker 镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71085054/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com