Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native Image Build Fails after upgrading dd-trace-java from 1.40.0 to 1.41.0 #8011

Closed
abdelmoez-guetat opened this issue Nov 25, 2024 · 8 comments
Assignees
Labels
Milestone

Comments

@abdelmoez-guetat
Copy link

Description

I am attempting to build a native image for my Spring Boot application using GraalVM, but I am encountering initialization issues related to classes during the build time. These issues have arisen after upgrading Datadog's Java APM agent from version 1.40.0 to 1.41.0.

When building the native image, I receive the following error messages:

Classes that should be initialized at runtime were initialized during image building:
- datadog.trace.api.Functions$PrefixJoin was unintentionally initialized at build time. To investigate further, use --trace-class-initialization=datadog.trace.api.Functions$PrefixJoin.
- datadog.trace.bootstrap.instrumentation.decorator.BaseDecorator was unintentionally initialized at build time. To investigate further, use --trace-class-initialization=datadog.trace.bootstrap.instrumentation.decorator.BaseDecorator.
- datadog.trace.bootstrap.instrumentation.decorator.AsyncResultDecorator was unintentionally initialized at build time. To investigate further, use --trace-class-initialization=datadog.trace.bootstrap.instrumentation.decorator.AsyncResultDecorator.

The setup details are as follows:
Java Version: 17
Spring Boot Version: 3.3.5
GraalVM Version: 17.0.11

Maven Plugin Configuration:

I am using Maven to build the project, and the following is my plugin configuration in the pom.xml file:

            <plugin>
                <groupId>org.graalvm.buildtools</groupId>
                <artifactId>native-maven-plugin</artifactId>
                <configuration>
                    <buildArgs>
                        <buildArg>-J-javaagent:dd-java-agent.jar</buildArg>
                        <buildArg>
                            --initialize-at-build-time=org.slf4j.helpers,datadog.okhttp3.internal.platform,net.logstash.logback
                        </buildArg>
                        <buildArg>--initialize-at-run-time=net.logstash.logback.appender.LogstashTcpSocketAppender
                        </buildArg>
                        <buildArg>--link-at-build-time=net.logstash.logback.appender</buildArg>
                        <buildArg>-H:+ReportExceptionStackTraces</buildArg>
                        <buildArg>-H:+MultiThreaded</buildArg>
                        <buildArg>-H:IncludeResources=.*\.xml</buildArg>
                    </buildArgs>
                    <imageName>${build.finalName}</imageName>
                </configuration>
            </plugin>

Additional Errors:

Error: Classes that should be initialized at run time got initialized during image building:
 datadog.trace.bootstrap.instrumentation.decorator.AsyncResultDecorator was unintentionally initialized at build time. org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService caused initialization of this class with the following trace: 
        at datadog.trace.bootstrap.instrumentation.decorator.AsyncResultDecorator.<clinit>(AsyncResultDecorator.java:19)
        at datadog.trace.instrumentation.reactor.core.ReactorAsyncResultSupportExtension.<clinit>(ReactorAsyncResultSupportExtension.java:11)
        at reactor.core.publisher.MonoJust.<init>(MonoJust.java:36)
        at reactor.core.publisher.Mono.just(Mono.java:754)
        at org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService.<clinit>(HandshakeWebSocketService.java:72)

datadog.trace.api.Functions$PrefixJoin was unintentionally initialized at build time. org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService caused initialization of this class with the following trace: 
        at datadog.trace.api.Functions$PrefixJoin.<clinit>(Functions.java:102)
        at datadog.trace.bootstrap.instrumentation.decorator.BaseDecorator.<clinit>(BaseDecorator.java:37)
        at datadog.trace.instrumentation.reactor.core.ReactorAsyncResultSupportExtension.<clinit>(ReactorAsyncResultSupportExtension.java:11)
        at reactor.core.publisher.MonoJust.<init>(MonoJust.java:36)
        at reactor.core.publisher.Mono.just(Mono.java:754)
        at org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService.<clinit>(HandshakeWebSocketService.java:72)

datadog.trace.bootstrap.instrumentation.decorator.BaseDecorator was unintentionally initialized at build time. org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService caused initialization of this class with the following trace: 
        at datadog.trace.bootstrap.instrumentation.decorator.BaseDecorator.<clinit>(BaseDecorator.java:23)
        at datadog.trace.instrumentation.reactor.core.ReactorAsyncResultSupportExtension.<clinit>(ReactorAsyncResultSupportExtension.java:11)
        at reactor.core.publisher.MonoJust.<init>(MonoJust.java:36)
        at reactor.core.publisher.Mono.just(Mono.java:754)
        at org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService.<clinit>(HandshakeWebSocketService.java:72)


com.oracle.svm.core.util.UserError$UserException: Classes that should be initialized at run time got initialized during image building:
 datadog.trace.bootstrap.instrumentation.decorator.AsyncResultDecorator was unintentionally initialized at build time. org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService caused initialization of this class with the following trace: 
        at datadog.trace.bootstrap.instrumentation.decorator.AsyncResultDecorator.<clinit>(AsyncResultDecorator.java:19)
        at datadog.trace.instrumentation.reactor.core.ReactorAsyncResultSupportExtension.<clinit>(ReactorAsyncResultSupportExtension.java:11)
        at reactor.core.publisher.MonoJust.<init>(MonoJust.java:36)
        at reactor.core.publisher.Mono.just(Mono.java:754)
        at org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService.<clinit>(HandshakeWebSocketService.java:72)

datadog.trace.api.Functions$PrefixJoin was unintentionally initialized at build time. org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService caused initialization of this class with the following trace: 
        at datadog.trace.api.Functions$PrefixJoin.<clinit>(Functions.java:102)
        at datadog.trace.bootstrap.instrumentation.decorator.BaseDecorator.<clinit>(BaseDecorator.java:37)
        at datadog.trace.instrumentation.reactor.core.ReactorAsyncResultSupportExtension.<clinit>(ReactorAsyncResultSupportExtension.java:11)
        at reactor.core.publisher.MonoJust.<init>(MonoJust.java:36)
        at reactor.core.publisher.Mono.just(Mono.java:754)
        at org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService.<clinit>(HandshakeWebSocketService.java:72)

datadog.trace.bootstrap.instrumentation.decorator.BaseDecorator was unintentionally initialized at build time. org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService caused initialization of this class with the following trace: 
        at datadog.trace.bootstrap.instrumentation.decorator.BaseDecorator.<clinit>(BaseDecorator.java:23)
        at datadog.trace.instrumentation.reactor.core.ReactorAsyncResultSupportExtension.<clinit>(ReactorAsyncResultSupportExtension.java:11)
        at reactor.core.publisher.MonoJust.<init>(MonoJust.java:36)
        at reactor.core.publisher.Mono.just(Mono.java:754)
        at org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService.<clinit>(HandshakeWebSocketService.java:72)
@mcculls mcculls self-assigned this Nov 26, 2024
@mcculls
Copy link
Contributor

mcculls commented Nov 26, 2024

Hi @abdelmoez-guetat this is a known bug which will be fixed in the next release

Until then you can add the following options as a workaround:

<buildArg>-Ddd.integration.reactive-streams.enabled=false</buildArg>
<buildArg>-Ddd.integration.reactor-core.enabled=false</buildArg>

@mimiyanwk
Copy link

Hi @abdelmoez-guetat this is a known bug which will be fixed in the next release

Until then you can add the following options as a workaround:

<buildArg>-Ddd.integration.reactive-streams.enabled=false</buildArg>
<buildArg>-Ddd.integration.reactor-core.enabled=false</buildArg>

it doesn't work for me and I have to use '--initialize-at-run-time=datadog.trace.agent.core.scopemanager.ContinuableScopeManager,datadog.trace.bootstrap.instrumentation.java.concurrent.QueueTimerHelper$RateLimiterHolder'.
Example for quarkus and dd-java-agent 1.43.0:
-Dquarkus.native.additional-build-args='-J-javaagent:/datadog-lib/dd-java-agent.jar,-J-Ddd.profiling.enabled=true,--enable-monitoring=heapdump,jfr,--initialize-at-run-time=datadog.trace.agent.core.scopemanager.ContinuableScopeManager,datadog.trace.bootstrap.instrumentation.java.concurrent.QueueTimerHelper$RateLimiterHolder'

@mcculls
Copy link
Contributor

mcculls commented Nov 27, 2024

@mimiyanwk the ContinuableScopeManager and QueueTimerHelper classes should not be initialized at build time because that would freeze certain things in place and cause issues later on at runtime. If they are showing up during native-image analysis then you are hitting a different issue.

The issue reported in the original description is about a known bug relating to AsyncResultDecorator to which the workaround is to disable both the reactive-streams and reactor-core integrations.

Can you provide an example that recreates the particular error you are seeing and attach it to a new issue for tracking purposes?

@mcculls
Copy link
Contributor

mcculls commented Nov 27, 2024

The native-image caused by AsyncResultDecorator should be fixed in v1.44.0 by #8012

@mcculls mcculls added this to the 1.44.0 milestone Nov 27, 2024
@mimiyanwk
Copy link

mimiyanwk commented Dec 2, 2024

Can you provide an example that recreates the particular error you are seeing and attach it to a new issue for tracking purposes?

Which error do you mean? As you mentioned, if the ContinuableScopeManager and QueueTimerHelper classes were initialized at run time, then there is no error.
I am just setting up datadog java tracer with quarkus native as described on the website https://docs.datadoghq.com/tracing/trace_collection/compatibility/java/?tab=quarkusnative

@mcculls
Copy link
Contributor

mcculls commented Dec 2, 2024

Hi @mimiyanwk, basically you shouldn't need to add any --initialize-at-build-time or --initialize-at-run-time settings for Datadog classes because the tracer is supposed to add any necessary options itself when it is attached to the native-image process. You should only need to add the extra JVM argument attaching the tracer.

This issue will be closed when v1.44.0 is released because the errors listed in the original description are fixed by #8012

You appear to be encountering a different issue because you mentioned above that the workaround for this particular issue "doesn't work for me".

Can you open a new issue and attach an example project that recreates the issues you see - thanks in advance

@mimiyanwk
Copy link

ok, I am going to open a new issue.
I didn't add any --initialize-at-build-time settings for Datadog classes.

Copy link
Contributor

🤖 This issue has been addressed in the latest release. Check full details in the Release Notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants