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] Uncaught exception java.lang.NoClassDefFoundError: Could not initialize class jnr.unixsocket.UnixSocketChannel in dd-profiler-http-dispatcher #7978

Open
khannedy opened this issue Nov 20, 2024 · 7 comments
Labels

Comments

@khannedy
Copy link

khannedy commented Nov 20, 2024

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)
@khannedy
Copy link
Author

we use lates datadog library from : https://dtdg.co/latest-java-tracer

@mcculls
Copy link
Contributor

mcculls commented Nov 20, 2024

Hi @khannedy, dd-java-agent does not currently support using unix-domain sockets with native-image - you have to use ports

@khannedy
Copy link
Author

thanks for the info @mcculls

it's working if using http port

@mimiyanwk
Copy link

Hi @khannedy, dd-java-agent does 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?

@mcculls
Copy link
Contributor

mcculls commented Nov 26, 2024

DD_TRACE_AGENT_URL=http://localhost:8126

@mimiyanwk
Copy link

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=. Or you can write your own initialization methods and call them explicitly from your main entry point.
Trace: Object was reached by
reading field java.util.concurrent.DelayQueue.leader of constant
java.util.concurrent.DelayQueue@65ebb4c4: [periodic task RollWindowTask with target datadog.trace.api.sampling.AdaptiveSam...
reading field datadog.trace.util.AgentTaskScheduler.workQueue of constant
datadog.trace.util.AgentTaskScheduler@34d71a78: datadog.trace.util.AgentTaskScheduler@34d71a78
scanning root datadog.trace.util.AgentTaskScheduler@34d71a78: datadog.trace.util.AgentTaskScheduler@34d71a78 embedded in
datadog.trace.agent.core.scopemanager.ContinuableScopeManager$RootIterationCleaner.scheduleFor(ContinuableScopeManager.java:334)
parsing method datadog.trace.agent.core.scopemanager.ContinuableScopeManager$RootIterationCleaner.scheduleFor(ContinuableScopeManager.java:333) reachable via the parsing context
at static root method.(Unknown Source)

@mcculls
Copy link
Contributor

mcculls commented Nov 26, 2024

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 #8011

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