opentelemetry-java icon indicating copy to clipboard operation
opentelemetry-java copied to clipboard

Fix graalvm compatibility

Open ericdallo opened this issue 10 months ago • 8 comments

This fix a graalvm compatibility with the logger api (only one I tested in my lib), this exports the graalvm config automatically for clients.

Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: An object of type 'io.opentelemetry.api.common.AttributeType' was found in the image heap. This type, however, is marked for initialization at image run time for the following reason: classes are initialized at run time by default.
This is not allowed for correctness reasons: All objects that are stored in the image heap must be initialized at build time.

You now have two options to resolve this:

1) If it is intended that objects of type 'io.opentelemetry.api.common.AttributeType' are persisted in the image heap, add

    '--initialize-at-build-time=io.opentelemetry.api.common.AttributeType'

to the native-image arguments. Note that initializing new types can store additional objects to the heap. It is advised to check the static fields of 'io.opentelemetry.api.common.AttributeType' to see if they are safe for build-time initialization,  and that they do not contain any sensitive data that should not become part of the image.

2) If these objects should not be stored in the image heap, you can use

    '--trace-object-instantiation=io.opentelemetry.api.common.AttributeType'

to find classes that instantiate these objects. Once you found such a class, you can mark it explicitly for run time initialization with

    '--initialize-at-run-time=<culprit>'

to prevent the instantiation of the object.

If you are seeing this message after upgrading to a new GraalVM release, this means that some objects ended up in the image heap without their type being marked with --initialize-at-build-time.
To fix this, include '--initialize-at-build-time=io.opentelemetry.api.common.AttributeType' in your configuration. If the classes do not originate from your code, it is advised to update all library or framework dependencies to the latest version before addressing this error.

The following detailed trace displays from which field in the code the object was reached.
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.classinitialization.ClassInitializationFeature.checkImageHeapInstance(ClassInitializationFeature.java:206)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisType.lambda$notifyObjectReachable$12(AnalysisType.java:659)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.ConcurrentLightHashSet.forEach(ConcurrentLightHashSet.java:149)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisType.notifyObjectReachable(AnalysisType.java:659)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.heap.ImageHeapScanner.onObjectReachable(ImageHeapScanner.java:586)
        ... 11 more

ericdallo avatar Feb 28 '25 14:02 ericdallo

CLA Signed

The committers listed above are authorized under a signed CLA.

  • :white_check_mark: login: ericdallo / name: Eric Dallo (8499295a612f0cc87d98a8fa3eab9aadd0ec15ff, ca60b963154559382db35b4ad6252352a36e53be)

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 89.85%. Comparing base (cd1f617) to head (8499295). :warning: Report is 333 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #7160   +/-   ##
=========================================
  Coverage     89.85%   89.85%           
  Complexity     6622     6622           
=========================================
  Files           740      740           
  Lines         20007    20007           
  Branches       1968     1968           
=========================================
  Hits          17978    17978           
  Misses         1439     1439           
  Partials        590      590           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Feb 28 '25 14:02 codecov[bot]

cc @jeanbisutti

trask avatar Feb 28 '25 15:02 trask

Hmm.. its not clear to me what the problem is with AttributeType that requires it to be handled with this special case.

Can you provide a repro of the issue? Would good to add it to our graal test suite.

jack-berg avatar Feb 28 '25 15:02 jack-berg

@ericdallo Could you please provide the GraalVM version for which the problem appears?

jeanbisutti avatar Feb 28 '25 16:02 jeanbisutti

@jeanbisutti

native-image 23.0.1 2024-10-15
GraalVM Runtime Environment GraalVM CE 23.0.1+11.1 (build 23.0.1+11-jvmci-b01)
Substrate VM GraalVM CE 23.0.1+11.1 (build 23.0.1+11, serial gc)

@jack-berg I reproed that using the log appender of timbre here on clojure-lsp, I can't spend more time on this though, so after this PR, I included on clojure-lsp here to fix my case meanwhile

ericdallo avatar Feb 28 '25 16:02 ericdallo

@jack-berg The native tests are executed with GraalVM 21: https://github.com/open-telemetry/opentelemetry-java/blob/cd1f61725c4ff3a312a42f7cea3bc9f04ef82435/.github/workflows/build.yml#L170 It may be worth to run them with version 23 as well (the last one).

jeanbisutti avatar Feb 28 '25 16:02 jeanbisutti

It may be worth to run them with version 23 as well (the last one).

See #7167

jack-berg avatar Mar 04 '25 15:03 jack-berg

Is this still needed/wanted? It's been open a while, and I don't have a problem with it, but let's either get it merged, or close it.

jkwatson avatar Sep 11 '25 16:09 jkwatson

It's still a improvement for default, I suggest merge it so users don't need to spend debugging I like I did

ericdallo avatar Sep 11 '25 17:09 ericdallo

Thank you for your contribution @ericdallo! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey.

otelbot[bot] avatar Sep 11 '25 17:09 otelbot[bot]