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

GraalVM - Improve compatibility with native images #6127

Closed
NicklasWallgren opened this issue Jan 7, 2024 · 3 comments · Fixed by #6139
Closed

GraalVM - Improve compatibility with native images #6127

NicklasWallgren opened this issue Jan 7, 2024 · 3 comments · Fixed by #6139
Labels
Bug Something isn't working

Comments

@NicklasWallgren
Copy link

NicklasWallgren commented Jan 7, 2024

Describe the bug
Unable to build a Spring Boot 3.2 application using Java 21 and GraalVM 22.3, using AOT native-image.

Steps to reproduce

<dependency>
    <groupId>io.opentelemetry</groupId>
    <artifactId>opentelemetry-exporter-otlp</artifactId>
</dependency>
@Configuration
public class ObservationConfiguration {

    @Bean
    public SpanExporter otlpSpanExporter() {
        return OtlpGrpcSpanExporter.builder()
            .setEndpoint("http://localhost:4317")
            .build();
    }

}

What did you expect to see?
My understanding is that opentelemetry has native-image support. So I'd expect the application to build without crashing or throwing an exception.

What did you see instead?

com.oracle.svm.core.util.VMError$HostedError: com.oracle.svm.core.util.UserError$UserException: Image heap writing found a class not seen during static analysis. Did a static field or an object referenced from a static field change during native image generation? For example, a lazily initialized cache could have been initialized during image generation, in which case you need to force eager initialization of the cache before static analysis or reset the cache using a field value recomputation.
    class: io.opentelemetry.sdk.common.export.RetryPolicy
  reachable through:
    object: [Ljava.lang.Class;@73d05767  of class: java.lang.Class[]
    object: com.oracle.svm.core.code.ImageCodeInfo@3b2d610e  of class: com.oracle.svm.core.code.ImageCodeInfo
    root: com.oracle.svm.core.code.ImageCodeInfo.prepareCodeInfo()

What version and what artifacts are you using?

 +- io.micrometer:micrometer-tracing-bridge-otel:jar:1.2.0:compile
[INFO] |  +- io.micrometer:micrometer-tracing:jar:1.2.0:compile
[INFO] |  |  +- io.micrometer:context-propagation:jar:1.1.0:compile
[INFO] |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- io.opentelemetry:opentelemetry-api:jar:1.31.0:compile
[INFO] |  |  \- io.opentelemetry:opentelemetry-context:jar:1.31.0:compile
[INFO] |  +- io.opentelemetry.semconv:opentelemetry-semconv:jar:1.21.0-alpha:compile
[INFO] |  +- io.opentelemetry:opentelemetry-sdk-common:jar:1.31.0:compile
[INFO] |  +- io.opentelemetry:opentelemetry-sdk-trace:jar:1.31.0:compile
[INFO] |  +- io.opentelemetry:opentelemetry-sdk:jar:1.31.0:compile
[INFO] |  +- io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv:jar:1.31.0-alpha:compile
[INFO] |  |  +- io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:jar:1.31.0:compile
[INFO] |  |  \- io.opentelemetry:opentelemetry-extension-incubator:jar:1.31.0-alpha:runtime
[INFO] |  \- io.opentelemetry:opentelemetry-extension-trace-propagators:jar:1.31.0:compile
[INFO] +- io.micrometer:micrometer-registry-otlp:jar:1.12.0:compile
[INFO] |  +- io.micrometer:micrometer-core:jar:1.12.0:compile
[INFO] |  |  +- org.hdrhistogram:HdrHistogram:jar:2.1.12:runtime
[INFO] |  |  \- org.latencyutils:LatencyUtils:jar:2.0.3:runtime
[INFO] |  \- io.opentelemetry.proto:opentelemetry-proto:jar:1.0.0-alpha:runtime
[INFO] |     \- com.google.protobuf:protobuf-java:jar:3.23.4:runtime
[INFO] +- io.opentelemetry:opentelemetry-exporter-otlp:jar:1.31.0:compile
[INFO] |  +- io.opentelemetry:opentelemetry-sdk-metrics:jar:1.31.0:compile
[INFO] |  +- io.opentelemetry:opentelemetry-sdk-logs:jar:1.31.0:compile
[INFO] |  |  \- io.opentelemetry:opentelemetry-api-events:jar:1.31.0-alpha:runtime
[INFO] |  +- io.opentelemetry:opentelemetry-exporter-otlp-common:jar:1.31.0:runtime
[INFO] |  |  \- io.opentelemetry:opentelemetry-exporter-common:jar:1.31.0:runtime
[INFO] |  +- io.opentelemetry:opentelemetry-exporter-sender-okhttp:jar:1.31.0:runtime

Environment
Compiler: "Graalvm 22.3"
MacOS

Additional context
I fixed the issue locally by adding;

{
  "name":"io.opentelemetry.sdk.common.export.AutoValue_RetryPolicy",
  "queryAllDeclaredMethods":true
},
{
  "name":"io.opentelemetry.sdk.common.export.RetryPolicy",
  "queryAllDeclaredMethods":true
}
@jack-berg
Copy link
Member

Hmm.. I can't recreate this. I also can't make sense of why the compile wouldn't be able to find RetryPolicy. By default, the configured RetryPolicy is null, and its only set if you call OtlpGrpcSpanExporterBuilder#setRetryPolicy. If the compile detects a call to set the retry policy, it would obviously see the class reference and include it. If the retry policy is never set, then there is no place in the code path that actually uses it, so there shouldn't be anything to trigger that error.

But clearly you've seen the error so something is going on. Would you be able to post a small reproduction app so I can analyze it closer?

@NicklasWallgren
Copy link
Author

Hmm.. I can't recreate this. I also can't make sense of why the compile wouldn't be able to find RetryPolicy. By default, the configured RetryPolicy is null, and its only set if you call OtlpGrpcSpanExporterBuilder#setRetryPolicy. If the compile detects a call to set the retry policy, it would obviously see the class reference and include it. If the retry policy is never set, then there is no place in the code path that actually uses it, so there shouldn't be anything to trigger that error.

But clearly you've seen the error so something is going on. Would you be able to post a small reproduction app so I can analyze it closer?

I've created a simple reproduction app, see https://github.com/NicklasWallgren/otpl-native-poc

./mvnw native:compile -Pnative -DskipTests

The issue is probably related to AutoValue which generates value classes such as AutoValue_RetryPolicy.

@jack-berg
Copy link
Member

Thanks for the repro. After looking closely, it turns out that your app requires a different version of graal than we are running in the build. After updating the version, I managed to recreate it in #6139 in this build.

Not a graal / native image expert so not sure what changed between the CI we were running before and the new version 21, but as you point out, adding reflect-config.json resolves the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants