[GraalVM] Uncaught exception java.lang.NoClassDefFoundError: Could not initialize class jnr.unixsocket.UnixSocketChannel in dd-profiler-http-dispatcher
We use datadog agent in native-image graalvm, but when deploy, we get error class not found
Nov 20, 2024 @ 10:20:02.241 | [dd.trace 2024-11-20 10:20:02:241 +0700] [dd-profiler-http-dispatcher] ERROR java.util.concurrent.ThreadPoolExecutor$Worker - Uncaught exception java.lang.NoClassDefFoundError: Could not initialize class jnr.unixsocket.UnixSocketChannel in dd-profiler-http-dispatcher
-- | --
| Nov 20, 2024 @ 10:20:02.241 | java.lang.NoClassDefFoundError: Could not initialize class jnr.unixsocket.UnixSocketChannel
| Nov 20, 2024 @ 10:20:02.241 | at datadog.common.socket.UnixDomainSocketFactory.createSocket(UnixDomainSocketFactory.java:38)
| Nov 20, 2024 @ 10:20:02.241 | at datadog.okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:241)
| Nov 20, 2024 @ 10:20:02.241 | at datadog.okhttp3.internal.connection.RealConnection.connect(RealConnection.java:167)
| Nov 20, 2024 @ 10:20:02.241 | at datadog.okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:258)
| Nov 20, 2024 @ 10:20:02.241 | at datadog.okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
| Nov 20, 2024 @ 10:20:02.241 | at datadog.okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
| Nov 20, 2024 @ 10:20:02.241 | at datadog.okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
| Nov 20, 2024 @ 10:20:02.241 | at datadog.okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
| Nov 20, 2024 @ 10:20:02.241 | at datadog.okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
| Nov 20, 2024 @ 10:20:02.241 | at datadog.okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
| Nov 20, 2024 @ 10:20:02.241 | at datadog.okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
| Nov 20, 2024 @ 10:20:02.241 | at datadog.okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
| Nov 20, 2024 @ 10:20:02.241 | at datadog.okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
| Nov 20, 2024 @ 10:20:02.241 | at datadog.okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
| Nov 20, 2024 @ 10:20:02.241 | at datadog.okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:127)
| Nov 20, 2024 @ 10:20:02.241 | at datadog.okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
| Nov 20, 2024 @ 10:20:02.241 | at datadog.okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
| Nov 20, 2024 @ 10:20:02.241 | at datadog.okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:257)
| Nov 20, 2024 @ 10:20:02.241 | at datadog.okhttp3.RealCall$AsyncCall.execute(RealCall.java:201)
| Nov 20, 2024 @ 10:20:02.241 | at datadog.okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
| Nov 20, 2024 @ 10:20:02.241 | at [email protected]/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
| Nov 20, 2024 @ 10:20:02.241 | at [email protected]/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
| Nov 20, 2024 @ 10:20:02.241 | at [email protected]/java.lang.Thread.runWith(Thread.java:1596)
| Nov 20, 2024 @ 10:20:02.241 | at [email protected]/java.lang.Thread.run(Thread.java:1583)
| Nov 20, 2024 @ 10:20:02.241 | at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:833)
| Nov 20, 2024 @ 10:20:02.241 | at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:211)
| Nov 20, 2024 @ 10:19:49.487 | [dd.trace 2024-11-20 10:19:49:486 +0700] [dd-task-scheduler] INFO datadog.communication.monitor.DDAgentStatsDConnection - Detected /var/run/datadog/dsd.socket. Using it to send StatsD data.
| Nov 20, 2024 @ 10:19:48.689 | [dd.trace 2024-11-20 10:19:48:689 +0700] [dd-task-scheduler] WARN com.datadog.profiling.controller.openjdk.events.SmapEntryFactory - Smap entry events could not be registered due to missing systemMap operation
we build the image using this command
RUN native-image \
-H:+UnlockExperimentalVMOptions \
-H:Name=/app/application \
-J-javaagent:/app/agent/dd-java-agent.jar \
-J-Ddd.profiling.enabled=true \
--enable-monitoring=heapdump,jfr \
--initialize-at-build-time="datadog.trace.api.Functions\$PrefixJoin,datadog.trace.bootstrap.instrumentation.decorator.BaseDecorator,datadog.trace.bootstrap.instrumentation.decorator.AsyncResultDecorator,datadog.trace.instrumentation.reactor.core.ReactorAsyncResultSupportExtension,datadog.trace.instrumentation.reactivestreams.ReactiveStreamsAsyncResultSupportExtension" \
--verbose \
--static \
--libc=musl \
--allow-incomplete-classpath \
--report-unsupported-elements-at-runtime \
-cp "$(cat /app/classpath.txt)" $(cat /app/mainclass.txt)
we use lates datadog library from : https://dtdg.co/latest-java-tracer
Hi @khannedy, dd-java-agent does not currently support using unix-domain sockets with native-image - you have to use ports
thanks for the info @mcculls
it's working if using http port
Hi @khannedy,
dd-java-agentdoes not currently support using unix-domain sockets with native-image - you have to use ports
can you show a example how to use http ports not unix-domain?
DD_TRACE_AGENT_URL=http://localhost:8126
DD_TRACE_AGENT_URL=http://localhost:8126
thank you, i will try it. I got the error when building native image:
Detailed message: Error: Detected a started Thread in the image heap. Thread name: dd-task-scheduler. Threads running in the image generator are no longer running at image runtime. If these objects should not be stored in the image heap, you can use
'--trace-object-instantiation=java.lang.Thread'
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.
The object was probably created by a class initializer and is reachable from a static field. You can request class initialization at image runtime by using the option --initialize-at-run-time=
The dd-task-scheduler thread should not be being created at build time, unless you're forcing native-image to load one of the core tracer types at build time (only types needed for instrumentation should be loaded at build time - the core tracer should be loaded at runtime). Sometimes Graal will suggest registering a class at build time, but the root cause when using the tracer is often different and adding those --initialize-at-build-time settings will lead to other issues.
In this case you should remove any extra --initialize-at-build-time settings you added relating to dd-java-agent and instead add
-Ddd.integration.reactive-streams.enabled=false
-Ddd.integration.reactor-core.enabled=false
to workaround https://github.com/DataDog/dd-trace-java/issues/8011