Paketo Buildpack for OpenTelemetry 在 Maven Spring Boot 2.5.12 应用中不起作用。

huangapple go评论53阅读模式
英文:

Paketo Buildpack for OpenTelemetry not working with maven spring boot 2.5.12 app

问题

以下是您要翻译的代码部分:

I'm trying to add OpenTelemetry automated instrumentation to our spring boot app but I can't get it working.

The app is deployed as a docker image and the image is created via the spring-boot-maven-plugin.

I've added an env section to the spring-boot-maven-plugin config in the pom.xml:

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <image>
                        <name>appname</name>
                        <env>
                            <BP_OPENTELEMETRY_ENABLED>true</BP_OPENTELEMETRY_ENABLED>
                        </env>
                    </image>
                </configuration>
            </plugin>

不包括代码的翻译:

我正在尝试为我们的Spring Boot应用程序添加OpenTelemetry自动化仪器,但我无法使其工作。

该应用程序部署为Docker映像,并且该映像是通过spring-boot-maven-plugin创建的。

我在pom.xml中的spring-boot-maven-plugin配置中添加了一个env部分:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <image>
            <name>appname</name>
            <env>
                <BP_OPENTELEMETRY_ENABLED>true</BP_OPENTELEMETRY_ENABLED>
            </env>
        </image>
    </configuration>
</plugin>

我不确定这是否是启用它的正确方式,但我很难确定这一步是否有效。

Docker映像是通过以下命令创建并运行的:

mvn clean spring-boot:build-image
docker compose -f app.yml up

我在app.yml文件中添加了环境变量(主机名已替换为XXXXXX):

services:
  appname:
    image: appname:latest
    environment:
      - SPRING_PROFILES_ACTIVE=docker-local
      - BPE_OTEL_TRACES_EXPORTER=zipkin
      - BPE_OTEL_EXPORTER_ZIPKIN_ENDPOINT=http://XXXXXX:9411/api/v2/spans
      - BPE_OTEL_SERVICE_NAME=appname
      - BPE_OTEL_JAVAAGENT_ENABLED=true

然而,我认为这些环境变量未设置,因为当我运行以下命令时,我看不到它们:

docker run --entrypoint launcher -it appname:latest bash -c set

我没有看到任何跟踪数据传输到Zipkin,也没有在日志中看到任何内容。

在没有Docker的情况下,一切都正常工作。

我试图弄清楚是否只需使用更新版本的Spring Boot,但我找不到确定的方法。

我找不到任何已经成功使用此功能的应用程序示例。

编辑以包括可行解决方案:

Martin Theiss的解决方案是正确的。以下是执行所有操作的pom.xml部分:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <image>
            <name>appname</name>
            <buildpacks>
                <buildpack>paketo-buildpacks/java</buildpack>
                <buildpack>gcr.io/paketo-buildpacks/opentelemetry</buildpack>
            </buildpacks>
            <env>
                <BP_OPENTELEMETRY_ENABLED>true</BP_OPENTELEMETRY_ENABLED>
                <BPE_OTEL_JAVAAGENT_ENABLED>true</BPE_OTEL_JAVAAGENT_ENABLED>
                <BPE_OTEL_TRACES_EXPORTER>zipkin</BPE_OTEL_TRACES_EXPORTER>
                <BPE_OTEL_EXPORTER_ZIPKIN_ENDPOINT>http://zipkinhost:9411/api/v2/spans</BPE_OTEL_EXPORTER_ZIPKIN_ENDPOINT>
                <BPE_OTEL_SERVICE_NAME>appname</BPE_OTEL_SERVICE_NAME>
            </env>
        </image>
    </configuration>
</plugin>

请注意,这会将跟踪数据直接发送到Zipkin。最终,我将会将跟踪数据发送到OpenTelemetry收集器。

还请注意,我错误地尝试将环境变量放在spring app.yml配置文件中。这些应该像上面那样放在pom.xml中。

英文:

I'm trying to add OpenTelemetry automated instrumentation to our spring boot app but I can't get it working.

The app is deployed as a docker image and the image is created via the spring-boot-maven-plugin.

I'm following these instructions: https://github.com/paketo-buildpacks/opentelemetry

I've added an env section to the spring-boot-maven-plugin config in the pom.xml:

        &lt;plugin&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
            &lt;executions&gt;
                &lt;execution&gt;
                    &lt;goals&gt;
                        &lt;goal&gt;repackage&lt;/goal&gt;
                    &lt;/goals&gt;
                &lt;/execution&gt;
            &lt;/executions&gt;
            &lt;configuration&gt;
                &lt;image&gt;
                    &lt;name&gt;appname&lt;/name&gt;
                    &lt;env&gt;
                        &lt;BP_OPENTELEMETRY_ENABLED&gt;true&lt;/BP_OPENTELEMETRY_ENABLED&gt;
                    &lt;/env&gt;
                &lt;/image&gt;
            &lt;/configuration&gt;
        &lt;/plugin&gt;

I'm not sure this is the correct way to enable it but I'm having a hard time determining whether that step is working or not.

The docker image is created and run with:

    mvn clean spring-boot:build-image
    docker compose -f app.yml up

I've added environment variables to app.yml file (hostname replaced with XXXXXX):

    services:
      appname:
        image: appname:latest
        environment:
          - SPRING_PROFILES_ACTIVE=docker-local
          - BPE_OTEL_TRACES_EXPORTER=zipkin
          - BPE_OTEL_EXPORTER_ZIPKIN_ENDPOINT=http://XXXXXX:9411/api/v2/spans
          - BPE_OTEL_SERVICE_NAME=appname
          - BPE_OTEL_JAVAAGENT_ENABLED=true

I don't think these environment variables are being set, however because I don't see them when I run:

> docker run --entrypoint launcher -it appname:latest bash -c set

I don't see any traces going to zipkin and I don't see anything in the logs.

Without docker, I have everything working fine.

I tried to figure out if I just need to use a more recent version of spring boot but I couldn't find a way to determine that.

I couldn't find any examples of apps that have this working.

Edit to include working solution:

Martin Theiss's solution is correct. Here is the section of the pom.xml that does everything:

        &lt;plugin&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
            &lt;executions&gt;
                &lt;execution&gt;
                    &lt;goals&gt;
                        &lt;goal&gt;repackage&lt;/goal&gt;
                    &lt;/goals&gt;
                &lt;/execution&gt;
            &lt;/executions&gt;
            &lt;configuration&gt;
                &lt;image&gt;
                    &lt;name&gt;appname&lt;/name&gt;
                    &lt;buildpacks&gt;
                        &lt;buildpack&gt;paketo-buildpacks/java&lt;/buildpack&gt;
                        &lt;buildpack&gt;gcr.io/paketo-buildpacks/opentelemetry&lt;/buildpack&gt;
                    &lt;/buildpacks&gt;
                    &lt;env&gt;
                        &lt;BP_OPENTELEMETRY_ENABLED&gt;true&lt;/BP_OPENTELEMETRY_ENABLED&gt;
                        &lt;BPE_OTEL_JAVAAGENT_ENABLED&gt;true&lt;/BPE_OTEL_JAVAAGENT_ENABLED&gt;
                        &lt;BPE_OTEL_TRACES_EXPORTER&gt;zipkin&lt;/BPE_OTEL_TRACES_EXPORTER&gt;
                        &lt;BPE_OTEL_EXPORTER_ZIPKIN_ENDPOINT&gt;http://zipkinhost:9411/api/v2/spans&lt;/BPE_OTEL_EXPORTER_ZIPKIN_ENDPOINT&gt;
                        &lt;BPE_OTEL_SERVICE_NAME&gt;appname&lt;/BPE_OTEL_SERVICE_NAME&gt;
                    &lt;/env&gt;
                &lt;/image&gt;
            &lt;/configuration&gt;
        &lt;/plugin&gt;

Note that this is sending traces directly to zipkin. Eventually I'll be sending traces to an opentelemetry collector.

Note also that I was wrong to try to put environment variables in the spring app.yml config file. These should be put in the pom.xml as per above.

答案1

得分: 2

OpenTelemetry构建包不包含在buildpacks/java中。您必须另外指定它。

<image>
    <buildpacks>
        <buildpack>paketo-buildpacks/java</buildpack>
        <buildpack>gcr.io/paketo-buildpacks/opentelemetry</buildpack>
    </buildpacks>
    <env>
        <BP_OPENTELEMETRY_ENABLED>true</BP_OPENTELEMETRY_ENABLED>
    </env>
</image>
英文:

OpenTelemetry buildpack is not contained in the buildpacks/java. You have to specify it additionally.

					&lt;image&gt;
						&lt;buildpacks&gt;
							&lt;buildpack&gt;paketo-buildpacks/java&lt;/buildpack&gt;
							&lt;buildpack&gt;gcr.io/paketo-buildpacks/opentelemetry&lt;/buildpack&gt;
						&lt;/buildpacks&gt;
						&lt;env&gt;
							&lt;BP_OPENTELEMETRY_ENABLED&gt;true&lt;/BP_OPENTELEMETRY_ENABLED&gt;
						&lt;/env&gt;
					&lt;/image&gt;

huangapple
  • 本文由 发表于 2023年2月18日 14:09:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/75491542.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定